Difference between revisions of "Regex"

From Wiki2
(Created page with "==regex== *^[ \t]+ //finds all the space and tabs *[1-9]\. //finds all the line numbers. (replace with #) *[A-E]\. //find A. etc (replace with ##) to clean special characte...")
 
Line 9: Line 9:


===sites===
===sites===
*http://rubular.com
*http://e-texteditor.com/blog/2010/beyond-vi
*http://e-texteditor.com/blog/2010/beyond-vi
*http://www.grymoire.com/Unix/Regular.html#uh-2
*http://www.grymoire.com/Unix/Regular.html#uh-2

Revision as of 17:54, 9 August 2013

regex

  • ^[ \t]+ //finds all the space and tabs
  • [1-9]\. //finds all the line numbers. (replace with #)
  • [A-E]\. //find A. etc (replace with ##)

to clean special characters from a string

$clean = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?$/i", "$1", $text);

sites

expressions

If you want to get'Aloha World'out

Input:

Hello World
Aloha World
Hey There

RegEx:

  \<div\sclass\=\"somename\"\>(?<Text>.*?)\<\/div\>

Yields:

Aloha World (note: In a single group named Text)