Solved

Need some Guidance on RegEx

Posted on 2013-12-08
10
241 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 30

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 15

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 30

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
 
LVL 15

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 30

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 15

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 30

Expert Comment

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

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 15

Author Closing Comment

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

Expert Comment

by:Marco Gasi
ID: 39704192
Glad to help you! On to the next.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…

744 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

14 Experts available now in Live!

Get 1:1 Help Now