We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide
Shortest match regex - any help
Horlock
Posts: 1,027 Forumite
in Techie Stuff
Hi hope this a suitable place to put this.
I'm trying to extract an expression in visual basic .net (but any regex help greatly appriciated).
my starting string is something like:
hello <personname> john <or/> fred <or/> terry <or/> bill <or/> jane </personname>
I want grab the person names!
As a start I would be happy with how to grab john.
My guess was
RegularExpressions.Regex.Replace(input, ".*<personname>(.*)<or/>.*", "$1").ToString
however this grabs
john <or/> fred <or/> terry <or/> bill <or/> jane
Unfortunately I can't just do
RegularExpressions.Regex.Replace(input, ".*>(^<*)<.*", "$1").ToString
because there is other markup in the string which is needed (ie the original string is actually slightly more like
hello <personname> john <or/> <dontlike> fred </dontlike> <or/> terry <or/> bill <or/> jane </personname>
Any help greatfully recieved (assuming it's possible - and I've posted in the correct place).
Ta
I'm trying to extract an expression in visual basic .net (but any regex help greatly appriciated).
my starting string is something like:
hello <personname> john <or/> fred <or/> terry <or/> bill <or/> jane </personname>
I want grab the person names!
As a start I would be happy with how to grab john.
My guess was
RegularExpressions.Regex.Replace(input, ".*<personname>(.*)<or/>.*", "$1").ToString
however this grabs
john <or/> fred <or/> terry <or/> bill <or/> jane
Unfortunately I can't just do
RegularExpressions.Regex.Replace(input, ".*>(^<*)<.*", "$1").ToString
because there is other markup in the string which is needed (ie the original string is actually slightly more like
hello <personname> john <or/> <dontlike> fred </dontlike> <or/> terry <or/> bill <or/> jane </personname>
Any help greatfully recieved (assuming it's possible - and I've posted in the correct place).
Ta
There is no intelligent life out there ... ask any goldfish!
0
Comments
-
In that case it might be easier to parse it as an XML document - see http://www.codeproject.com/vb/net/parsefilecode.asp.Horlock wrote:It is part of a tag-balance document - if that helps0 -
Wow that would probably be marvelous if I hadn't gone so far in the code already - still it might be worth my while to backtrack and use it - but there are quite a few classes which might need to be scrapped - though it may end more elegantly - I'll have to think about it.Chippy_Minton wrote:In that case it might be easier to parse it as an XML document - see http://www.codeproject.com/vb/net/parsefilecode.asp.
Thanks loads though - afraid I can only click thanks once!There is no intelligent life out there ... ask any goldfish!0 -
Just found an easy work around - I think - but I'm not going to implement it tonight.
If I start from the other end.
Ie first I find Jane
then I find bill etc etc
I'm fairly confident that that will workThere is no intelligent life out there ... ask any goldfish!0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 353.6K Banking & Borrowing
- 254.2K Reduce Debt & Boost Income
- 455.1K Spending & Discounts
- 246.7K Work, Benefits & Business
- 603.1K Mortgages, Homes & Bills
- 178.1K Life & Family
- 260.7K Travel & Transport
- 1.5M Hobbies & Leisure
- 16K Discuss & Feedback
- 37.7K Read-Only Boards