split Tel and Fax numbers from this string using regex -


consider below given string

po box number 1234, ca - 3265 tel: +1-200-200-2000 fax: +1-200-200-2001
po box number 1234, ca - 3265 service: +1-200-200-2002 \ +1-200-200-2022 f : +1-200-200-2003
po box number 1234, ca - 3265 care: +1-200-200-2004 f : +1-200-200-2005
po box number 1234, ca - 3265 fire: +1-200-200-2006 fax : +1-200-200-2007
po box number 1234, ca - 3265 help: +1-200-200-2008 fax - +1-200-200-2009
po box number 1234, ca - 3265 fax : (+123)-4567890 \ (+123)-4567891

the regular expression mentioned below 1 i'm using finding fax number in different representation

(?:(f|f)((a|a)(x|x))?(?:\s?(\-|\:)?\s?))(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30} 

ex: above regex match fax given string shown below

fax: +1-200-200-2001
f : +1-200-200-2003
f : +1-200-200-2005
fax : +1-200-200-2007
fax - +1-200-200-2009
fax : (+123)-4567890 \ (+123)-4567891

note: considering phone numbers rest of numbers available in given text apart taking fax.
ex: tel: +1-200-200-2000
service: +1-200-200-2002 \ +1-200-200-2022
care: +1-200-200-2004
fire: +1-200-200-2006
help: +1-200-200-2008

so need phone numbers text not starts [faxfax]. have tried [^faxfax] changing above specified regular expression couldn't desired result.please me out write regular expression this.

you can use (*skip)(*fail):

(?:(f|f)((a|a)(x|x))?(?:\s?(\-|\:)?\s?))(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30}(*skip)(*fail)|(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30} 

see demo

edit: explanation of (*skip)(*fail} suggested in comments.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -