php - Regular expression to find a string included between two bars and containing certain words -


After learning this I always forget the correct regex. I want to remove the ISBN number from the string.

string: english | ISBN: 1285463234. 2014 | 49 9 pages. PDF | 28 MB

Goal to remove: 1285463234

You can try the regex below to remove the ISBN number,

  ISBN: \ s * \ K \ d +  

Your PHP code will be,

  & lt ;? Php $ mystring = 'english | ISBN: 1285463234. 2014 | 49 9 pages. PDF | 28 MB '; $ Regex = '~ ISBN: \ s * \ K \ d + ~'; If (preg_match ($ regex, $ mystring, $ m)) $ $ yourmatch = $ m [0]; Echo $ yourmatch; }? & Gt; // = & gt; 1285463234  Explanation:   
  • ISBN: string ISBN:
  • \ s * matches zero or more spaces.
  • \ k discards previously matched characters (i.e., isbin: )
  • \ d + matches one or more digits.

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -