AlignSD
AlignSD

Reputation: 21

RegEx Match string between angle brackets and ignore newline

I think I've nearly got this figured out but I cant for life of me figure out why its removing the first part of "little rock"

Heres the string I'm working with:

"<Telerik.Sitefinity.GeoLocations.Model.Address>\n <City>Little Rock</City>

Here's my RegEX:

/(?<=>[^\\n]).+?(?=\<)/gm

And here's my results so far:

ittle Rock

I'm trying to capture the text between the angled brackets but also ignore any \n values. Any help would be greatly appreciated.

Upvotes: 2

Views: 538

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626926

You can use

(?<=>(?!\\n))[^<>]*(?=<)

See the regex demo. Details:

  • (?<=>(?!\\n)) - a positive lookbehind that requires (immediately to the left of the current location) a > char not immediately followed with \n two-char sequence to appear immediately to the left of the current location
  • [^<>]* - zero or more chars other than < and >
  • (?=<) - a positive lookahead that requires < char at the right of the current location.

Variations

(?<=>(?!\\n)).*?(?=<)
(?<=>(?!\\n))[^<>]*

Upvotes: 3

Related Questions