Solved

Help with regular expression

Posted on 2011-09-05
17
369 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:bongii
  • 4
  • 4
  • 3
  • +5
17 Comments
 
LVL 84

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:bongii
ID: 36483752
ozo: nothing :/

EaswaramP: How can i  enable this option?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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:bongii
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 63

Accepted Solution

by:
Fernando Soto earned 250 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 250 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:bongii
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 84

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:bongii
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

778 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