I have a string as follows:
<String>VariableText</String>
I need a regex to identify the “VariableText” value within the node.
As the text suggests, the value could be variable.
How could this be achieved using regex?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, there are two common regex patterns to get ‘something’ that’s clearly delimited:
/%PatternForOpeningDelimiter%(.+?)%PatternForClosingDelimiter%/… or, in your case:
The content will be stored in
$1variable./(?<=%PatternForOpeningDelimiter%).+?(?=%PatternForClosingDelimiter%)/… or, in your case:
This pattern will cover ‘the required content’, and there’s no need to use regex variables (
$1,$2, etc.)Won’t hurt to be aware, though, that variable-length patterns (such as
(?<=\d+), for example) can be used as look-behind expressions in .NET regex flavor (credits to @Alan Moore for that helpful observation), but many others lack this feature (or support it partially).