Learn, Share, Build

247
October 08, 2017, at 01:47 AM

I am looking a regular expression that contains two logic: 1. Does not contain any white space 2. Must contain (/ or . or both) . Number of (/ or .) may be one or multiple.

$text = "Hi jaghdja ahja.ja//hda manmna.bnm bana na/bbnavn.com"; //for an example
//expecting output an array("ahja.ja//hda","manmna.bnm","na/bbnavn.com");

What I am using

preg_match_all("#([^\s]|\.|\/)*#",$a,$arr);
print_r($arr);
Answer 1

You can use this regex:

[^/.\s]*[./]\S*

Code:

preg_match_all('~[^/.\s]*[./]\S*~', $a, $arr);
print_r($arr);

RegEx Demo

RegEx Breakup:

  • [^/.\s]*: Match a character that is not a / and not a . and not a white-space
  • [./]: Match a dot or forward slash
  • \S*: Match 0 or more non-white-space character
Rent Charter Buses Company
READ ALSO
Learn, Share, Build

Learn, Share, Build

I would like to learn how to excute shell commands right from mysqlMy MYSQL version is 5

227
Learn, Share, Build

Learn, Share, Build

I am at the stage of the OAuth flow where I get the OAuth verifier and have to use it to get the permanent token, however I encounter the error "Invalid oauth_verifier parameter"

223
Learn, Share, Build

Learn, Share, Build

I would like to catch somehow the laravel error, warning messageI don't want to disable them from the config/app

218
Learn, Share, Build

Learn, Share, Build

WE have to buy a Wordpress theme from ThemeForest I have uploaded a theme in my hosting but I have faced an error in Header Any solution, please

270