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
Solved

Need some Guidance on RegEx

Posted on 2013-12-08
10
249 Views
Last Modified: 2013-12-08
Hi, I need a Code where i can fetch the date of the following format. I am looking for Regular expression but as i am very basic in RegEx, so can't find a way to figure out

21 August , 2010 - 19 March, 2011 

November 14, 2011 - February 30, 2012

Open in new window



The dates and the months and the year can be changed [but the pattern will not change]
0
Comment
  • 6
  • 4
10 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39704049
This grabs the first two dates without the - :

\b\d{2}\s[a-zA-Z]+\s?,\s\d{4}\b

and this grabs the secnd two dates, always without  - :

\b[a-zA-Z]+\s\d{2},\s\d{4}\b
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39704125
i want to grab the both with - sign, how will that be a combination

Regards
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39704145
This for the first:

\b\d{2}\s[a-zA-Z]+\s?,\s\d{4}\s-\s\d{2}\s[a-zA-Z]+\s?,\s\d{4}\b

and this for the second:

\b[a-zA-Z]+\s\d{2},\s\d{4}\s-\s[a-zA-Z]+\s\d{2},\s\d{4}\b
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39704158
Thanks Budy, if you can help more how can i find a string of a link and email address from a string

the following string like

This is the world and i am now testing with the following string. The String is http://www.domain.com/classess/dataformat/anythingbeyon and let us see where we get this. This is the email address of the following, robert junior <a@a.com>

both should be found differently

Regards
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 39704179
This for the url

\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]

gets http://www.domain.com/classess/dataformat/anythingbeyon from 'The String is http://www.domain.com/classess/dataformat/anythingbeyon and let us see where we get this'

This for the email:

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b

gets a@a.com from robert junior <a@a.com>
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39704184
Hi for url i have this:

(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~##?&//=]+)

i used ## two times as coldfusion will escape one when it gets compiled, but this has a limitation as it checks for http, what if i have https:, ftp or neitehr ftp http or https

please guide
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39704188
The regex I provided above works with all protocols: why don't you use it?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39704189
Anyway, you can modify your regex this way:

 (((f|ht){1}tp(s)?://)[-a-zA-Z0-9@:%_\+.~##?&//=]+)
0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 39704190
Thanks Pal
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39704192
Glad to help you! On to the next.
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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 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