I am using this (?<=Postcode:).* Which works perfectly except it also includes text from the following list(li) how can I change this to include just the line where “postcode” is found.
I am using this (?<=Postcode:).* Which works perfectly except it also includes text from
Share
Something like this should work:
This will match all alphanumeric characters and spaces following
Postcode:. It will stop when it finds something else (for example, a<li>tag, which I assume is what you meant by “the following list”).Explanation: this portion of the regex
[...]is a character class. It will match anything in the collection of characters contained inside. In the above example, it matches any number of alphanumeric characters and spaces. If you also want to match, say,-and., you could edit it like this:Note that
-and.had to be escaped because they are both special characters:.matches any character, and-within a character class is used for ranges, such as[a-h0-9].