ex: <a><strike>example data in here</strike></a>
I want everything inside the a tag, to the end
/<a>([^<]*)<\/a>/
It works when there are no additional tags within the <a>
tag, but what if there are?
I want to know if you can tell it to grab everything up to [^</a>]
instead of [^<]
only.
Doing it with /<a>(.*)<\/a>/
doesn't work well. Sometimes I get everything in the <a>
tag and other times I get tons of lines included in that call.
A regular expression to match everything before a specific character makes use of a wildcard character and a capture group to store the matched value. Another method involves using a negated character class combined with an anchor. Let's investigate various methods of writing this.
$ means "Match the end of the string" (the position after the last character in the string).
Java regex to match specific word Strictly speaking, “\b” matches in these three positions: Before the first character in the data, if the first character is a word character. After the last character in the data, if the last character is a word character.
Prepare a Text question type. Go to the question's Settings. Go to Validation Criteria and choose the Manually enter your validation logic in XLSForm code option. In the Validation Code box, enter your regex formula between the quotation marks (' ') of the regex(., ' ') format.
/<a>(.*?)<\/a>/
should work. The ? makes it lazy, so it grabs as little as possible before matching the </a>
part. but using . will mean that it matches everything until it finds </a>
. If you want to be able to match across lines, you can use the following if with preg_match
/<a>(.*?)<\/a>/s
The "s" at the end puts the regular expression in "single line" mode, which means the . character matches all characters including new lines. See other useful modifiers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With