Regular Expressions 101

Save & Manage Regex

  • Current Version: 12
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

$re = '/([0-9]+)\s+(\w+,?)\s+(\w+).*?\r?\n•\s+([\s\S]*?)\s+[0-9]+\s\|.*\s*/u'; $str = '1 el, la art the • esa mujer era la mujer que yo quería ser 100 | 2037803 2 de prep of, from • el hijo de un hermano mío 100 | 1319834 3 que conj that, which • dice que no 100 | 662653 4 y conj and • él y ella sabían leer y escribir 100 | 562162 5 a prep to, at • se fue a la cama 100 | 529899 6 en prep in, on • no está en la casa 100 | 507233 7 un art a, an • era un hombre simpático 100 | 434022 8 ser v to be (norm) • es nuevo, es bueno 100 | 374194 +o 9 se pron [“reflexive” marker] • la abuela se acostó tranquila 100 | 329012 10 no adv no • no hay modo de negar nada 100 | 257365 +o 11 haber v to have (+Ved) • no ha dicho nada 100 | 196962 12 por prep by, for, through • así fue por mucho tiempo 100 | 190975 13 con prep with • hay un hombre con ella 100 | 184597 14 su adj his/her/their/your (–fam) • ¿quién era? ¿Su hermana? ¿Su amiga? 100 | 187810 15 para prep for, to, in order to • ¡tengo una sorpresa sensacional para ti! 100 | 126061 16 como conj like, as • ser compositor en España es como ser torero en Finlandia 100 | 106840 17 estar v to be (location, change from norm) • él está en el trabajo 100 | 106429 +o 18 tener v to have • estaba seguro de tener buena memoria 100 | 106642 +o 19 le pron [3rd person] (indir obj) • nunca le dijo la verdad 100 | 98211 20 lo art the (+ n) • lo mejor es estudiar mucho 100 | 91035 21 lo pron [3rd person] (dir obj-m) • lo compré en la tienda 100 | 92519 22 todo adj all, every • todos los hombres son iguales 100 | 88057 23 pero conj but, yet, except • no significa nada para mí, pero no puedo olvidarla 100 | 82435 +o 24 más adj more • él necesitaba más dinero 100 | 92352 25 hacer v to do, make • he podido hacer lo que me gusta 100 | 81619 26 o conj or • sí esperaba uno o dos muertos 100 | 82444 27 poder v to be able to; can • ¡se hace lo que se puede! 100 | 76738 28 decir v to tell, say • parece que dice la verdad 100 | 79343 +o 29 este adj this (m) [esta (f)] • y entendía estas cosas muy bien 100 | 80544 30 ir v to go • me habían invitado a ir a su casa 100 | 70352 +o 31 otro adj other, another • ¿por qué no podía ser otra cosa? 100 | 61726 32 ese adj that (m) [esa (f)] • ¿dónde viven esas mujeres? 100 | 60989 +o 33 la pron [3rd person] (dir obj-f) • la puso en su bolsillo 100 | 55523 34 si conj if, whether • si quiere cazar, vamos a cazar 100 | 53608 35 me pron me (obj) • ¿cuando me va a llamar? 97 | 95577 +o 36 ya adv already, still • su marido ya ha dicho todo 100 | 46778 +o 37 ver v to see • había que subir para ver las ruinas 100 | 45854 +o 38 porque conj because • lo vendo sólo porque tengo un apuro muy grande 100 | 44500 +o 39 dar v to give • me dio esta carta para Ud. 100 | 40233 40 cuando conj when • aquella es de mis nietos, cuando eran bebés 100 | 39726 41 él pron he, [ellos] them (m) • él es bastante simpático 100 | 38597 42 muy adv very, really • está muy contento con mi trabajo 100 | 39558 +o 43 sin prep without • se habían quedado sin dinero 100 | 40432 44 vez nf time (specific occurrence) • es la primera vez que estoy junto al mar 100 | 35286 45 mucho adj much, many, a lot (adv) • por lo visto tienen mucho dinero 100 | 36391 +o 46 saber v to know (a fact), find out • ellos lo saben y lo reconocen 100 | 37092 +o 47 qué pron what?, which?, how (+ adj)! • no sé qué voy a hacer 100 | 42000 +o 48 sobre prep on top of, over, about • dejó el papel sobre la mesa y se fue 100 | 35038 49 mi adj my • mi casa es su casa 99 | 45636 +o 50 alguno adj some, someone (pron) • habló algunas palabras con el agente de negocios 100 | 30485 51 mismo adj same • pronunciando el mismo discurso en siete idiomas 100 | 29569 52 yo pron I (subj) • ¡Yo soy el padre! 98 | 54635 +o 53 también adv also • y también van a estar los otros 100 | 33348 54 hasta prep until, up to, even (adv) • toda la noche, hasta las tres de la mañana 100 | 29506 55 año nm year • no lo supo hasta casi un año después 100 | 33053 56 dos num two • de allí salieron dos hermanas solteras 100 | 27733 57 querer v to want, love • quiero que este proceso salga con limpieza 100 | 28696 +o 58 entre prep between, among • la cosa es entre tú y yo 100 | 30756 59 así adv like that • la vida es así 100 | 24832 60 primero adj first • las primeras palabras que nos enseñan a leer y escribir 100 | 26553 61 desde prep from, since • lo había pensado desde el primer momento 100 | 25288 62 grande adj large, great, big • lo ha mirado a los grandes ojos negros 100 | 25963 63 eso pron that (n) • y eso no es todo 99 | 31636 +o 64 ni conj not even, neither, nor • pero ni eso me tranquilizó 100 | 24261 65 nos pron us (obj) • nos vio en la calle 99 | 26349 +o 66 llegar v to arrive • como para llegar hasta el fondo de las almas 100 | 22878 67 pasar v to pass, spend (time) • tras la ventana lo veo pasar una y otra vez 100 | 22466 68 tiempo nm time (general), weather • he estado mucho tiempo con ella 100 | 22432 69 ella pron she, [ellas] them (f) • ella es muy estudiosa 100 | 24770 70 sí adv yes • quiero una respuesta concreta: sí o no 100 | 33828 +o 71 día nm day • cada día hay más problemas 100 | 24715 72 uno num one • hay uno que ya lo está haciendo 100 | 21407 +o 73 bien adv well • y entonces hice bien en quedarme 100 | 21589 +o 74 poco adj little, few, a little bit (adv) • trabajó poco tiempo con él 100 | 20986 75 deber v should, ought to; to owe • te debes calmar, le aconsejó T. 100 | 22232 76 entonces adv so, then • vamos entonces a cambiarlo 100 | 23548 +o 77 poner v to put (on), get (+adj) • puso el cuchillo en manos de M. 100 | 20330 78 cosa nf thing • estoy ya interesado en otra cosa 100 | 23943 +o 79 tanto adj so much, so many • no podía creer que haya tanta gente junta 100 | 20531 80 hombre nm man, mankind, husband • yo soy un hombre de pocas necesidades 100 | 20292 81 parecer v to seem, look like • parecía dormir, tan inmóvil estaba 100 | 19964 82 nuestro adj our • no servía para nuestro país porque somos diferentes 100 | 20666 83 tan adv such, as, too, so • en esa mujer está todo; y por eso es tan maravillosa 100 | 19002 84 donde conj where • yo sé donde está la llave 100 | 18852 85 ahora adv now • lo importante ahora es contarte lo que le pasó 100 | 21030 +o 86 parte nf part, portion • el arte es una parte tan importante de la cultura 100 | 20319 87 después adv after • vamos a dar un paseo después de comer 100 | 20229 88 vida nf life • ha dedicado toda la vida a la música 100 | 18045 89 quedar v to remain, stay • el aire empezó a quedarse quieto 100 | 18152 90 siempre adv always, forever • siempre ha sido así 100 | 17689 91 creer v to believe, think • creo en la justicia de Dios 100 | 21257 +o 92 hablar v to speak, talk • algunos hablan el idioma romaní 100 | 19006 +o 93 llevar v to take, carry • colgado al hombro llevaba un bolso 100 | 17062 94 dejar v to let, leave • ella no dejó que yo lo olvidara 100 | 18185 95 nada pron nothing, (not) at all • no hay nada que hacer 100 | 19365 +o 96 cada adj each, every • de aprender cada día un poco más 100 | 17155 97 seguir v to follow, keep on • el calor sofocante que sigue al mediodía 100 | 16104 98 menos adj less, fewer • no vale más ni menos que la anterior 100 | 15527 99 nuevo adj new • marcaba el comienzo de una nueva vida para mí 100 | 17381 100 encontrar v to find • encontró un lugar apropiado para instalar la sucursal 100 | 15556'; $subst = "\1\t\2\t\3\t\4\t\n"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php