Solved

Need some Guidance on RegEx

Posted on 2013-12-08
10
247 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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…

803 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