Ready, steady… save!
You don’t need a chart to join in. Here are 2 ways to record your savings:
1. Cross it off
Pop a chart into your first post. Saved an amount? Cross it out! Read more »
£0.01 £0.02 £0.03
2. Write it down
Skip the chart and add updates to your first post. Read more »
“Another +£3 saved today. Go me!”
Use +£ before each new saving so it counts towards your total.
📨 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!
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
- 355.9K Banking & Borrowing
- 255K Reduce Debt & Boost Income
- 456.2K Spending & Discounts
- 248.4K Work, Benefits & Business
- 606.1K Mortgages, Homes & Bills
- 179K Life & Family
- 263.9K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.7K Read-Only Boards