?
Solved

Help with regular expression

Posted on 2011-09-05
17
Medium Priority
?
381 Views
Last Modified: 2013-12-17
hi guys.
I am trying to get an regular expression to grab the text "EE", but it dosen´t work:

Can somebody help?

My regex:
<b>Name:</b>[\s\S](.*?)

The code:
<span class="content">
          <b>Name:</b>
          EE
</span>
0
Comment
Question by:Jesper Christensen
  • 4
  • 4
  • 3
  • +5
17 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 36483612
what happens if you change [\s\S] to \s*
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36483690
Set multiline option in your Regex as true as well.
0
 

Author Comment

by:Jesper Christensen
ID: 36483752
ozo: nothing :/

EaswaramP: How can i  enable this option?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:andrewssd3
ID: 36483787
Try

<b>Name:</b>[\r\l]+(.*?)[\r\l]+<

0
 
LVL 8

Expert Comment

by:guvera
ID: 36483825
Hi,

GetText:\s*[\'\"]([^\'\"]+)[\'\"] If you use .NET's named capture from System.Text.RegularExpressions, the regex can be modified as follows:

GetText:\s*[\'\"](?<mytext>[^\'\"]+)[\'\"] ...and your targeted text is in the match group "mytext"

Please check the below our experts links comments
http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_24465093.html.

Also check it for learning Simple examples demonstrating the [ regexp ] command  in the below link.
http://wiki.tcl.tk/989

Regards
Guvera
0
 

Author Comment

by:Jesper Christensen
ID: 36483865
andrewssd3: It dosen´t work.

OMG I hate reg exp :/

Why hasent somebody made a tool, which allow me to mark sa text in a html context and press "Build expression" :)
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 36483979
Hi bongii;

Try this regex pattern, it should give you what you need.

<b>Name:</b>\s+([^<]+)

Fernando
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36484578
@EaswaranP
Set multiline option in your Regex as true as well.
Multiline would serve no purpose here. Singleline would be the intended modifier.

@bongii
Why hasent somebody made a tool, which allow me to mark sa text in a html context and press "Build expression" :)
Well there is, but you have to pay for it: http://www.regexmagic.com/

I offer a slight tweak to FernandoSoto's pattern, just to eliminate the trailing whitespace on the captured text:

<b>Name:</b>\s+(\S+)

Open in new window

0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 36485495
You can use this pattern as well:

(?m)(?<=<b>Name:</b>[^\S]+)[^< ]+
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36485600
@Shahan_Developer
The multiline modifier serves no purpose in your pattern. Also, isn't it a bit complicated to say whitespace as "[^\S]" when "\s" would suffice?
0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 1000 total points
ID: 36485627
Ohh!

>>>The multiline modifier serves no purpose in your pattern
I decided to work on it from different point of view and left (?m) intact (checked with online tester) so could not trace :S

>>>isn't it a bit complicated to say whitespace as "[^\S]"
Right. but still it will not produce wrong result.

The patten should be:
(?<=<b>Name:</b>\s+)[^< ]+

it gives "EE"
0
 

Author Comment

by:Jesper Christensen
ID: 36486734
The pattern posted by Fernando works perfect. Thanks.
<b>Name:</b>\s+([^<]+)

Can you also help me get the link from this context:
<a class="link" title="test" href="http://www.link.com">test</a>
I need the output :http://www.link.com
0
 
LVL 85

Expert Comment

by:ozo
ID: 36486749
<b>Name:</b>\s(.*)
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 36487675
@bongii:

Do you need this:
          EE----------------> EE along with spaces
or:
EE ------------------>EE without spaces

My pattern gives "EE" not "          EE".
0
 

Author Comment

by:Jesper Christensen
ID: 36487692
Ahh ok Shahan. Thx :)

What about this:

<a class="link" title="test" href="http://www.link.com">test</a>
I need the output :http://www.link.com
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36488402
My pattern gives "EE" not "          EE".
Funny....   So does mine.  *sigh*
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 36489346
@bongii

Check this pattern:

(?<=<a[\sa-zA-z="]+href=")([^>]+)(?=".*</a>)

gives:
http://www.link.com
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question