Solved

Help with regular expression

Posted on 2011-09-05
17
368 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
Comment Utility
what happens if you change [\s\S] to \s*
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
Comment Utility
Set multiline option in your Regex as true as well.
0
 

Author Comment

by:bongii
Comment Utility
ozo: nothing :/

EaswaramP: How can i  enable this option?
0
 
LVL 17

Expert Comment

by:andrewssd3
Comment Utility
Try

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

0
 
LVL 8

Expert Comment

by:guvera
Comment Utility
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
Comment Utility
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 62

Accepted Solution

by:
Fernando Soto earned 250 total points
Comment Utility
Hi bongii;

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

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

Fernando
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
@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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 19

Expert Comment

by:Shahan Ayyub
Comment Utility
You can use this pattern as well:

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

Expert Comment

by:käµfm³d 👽
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
<b>Name:</b>\s(.*)
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
Comment Utility
@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
Comment Utility
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 74

Expert Comment

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

Expert Comment

by:Shahan Ayyub
Comment Utility
@bongii

Check this pattern:

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

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
LINQ question 7 20
How do I bind the results to a grid 3 20
Limiting string to two deciamls 18 29
String manipulation 15 48
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now