Reputation:
This is my string:
<address>tel+1234567890</address>
This is my regex:
([\d].*<)
which matches this:
1234567890<
but I dont want to match the last <
character.
Upvotes: 0
Views: 51
Reputation: 51330
You can use a positive lookahead:
\d+(?=<)
The (?=
...)
syntax makes sure what's inside the parens matches at that position, without moving the match cursor forward, thus without consuming the input string. It's also called a zero-width assertion.
By the way, the square brackets in [\d]
are redundant, so you can omit them. Also, I've changed the regex, but perhaps you really meant to match this:
\d.*?(?=<)
This pattern matches everything between a digit and a <
, including the digit. It makes use of an ungreedy quantifier (*?
) to match up until the first <
if there are several.
Upvotes: 2