Solved

Help with regular expression

Posted on 2011-09-05
17
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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