I am searching for a pattern not inside <> characters.
For the given string "GKDLSD<span>DLK</span>DGEE", the regex /(s)/i should only return once. What is a regular expression I can use? The above example is very simplified, but that is definitely what I need is a way for the regex to only match characters outside of the html tags
Matching a pattern only outside <>tags
Moderator: General Moderators
Re: Matching a pattern only outside <>tags
Did you want the code in a long string without the html tags or each of the non html text as array?
This isn't that pretty but should do the trick if you wan't a string with the non html code.
If you wanted it in an array you could use
Then just split on @SPLIT@ and you will have all the non html values in an array.
Test it on http://regex.larsolavtorvik.com/ and see if it works like you wan't.
This isn't that pretty but should do the trick if you wan't a string with the non html code.
Code: Select all
preg_replace('/(<[^>]+>)/', ' ', 'GKDLSD<span>DLK</span>DGEE');Code: Select all
preg_replace('/(<[^>]+>)/', '@SPLIT@', 'GKDLSD<span>DLK</span>DGEE');Test it on http://regex.larsolavtorvik.com/ and see if it works like you wan't.
Re: Matching a pattern only outside <>tags
Hey, nice tool! Thanks.aCa wrote:Test it on http://regex.larsolavtorvik.com/ and see if it works like you wan't.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Matching a pattern only outside <>tags
Well done!