Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

~
~
guxm

Test String

Substitution

Processing...

Code Generator

Generated Code

import Foundation // WARNING: You included a flag that Swift doesn't support: u // When this flag is set, it makes the pattern and subject strings to be treated as unicode. // Swift already treats the pattern and subject strings as unicode by default, so including this flag is redundant. let pattern = #""" ^ (?<frequency>[0-9]+) \W+ (?<word>\pL+(?:,\h\pL+|\W)*) \h+ (?<gender> [\pL()]+ (?:, \h* [\pL()]+)* ) \h+ (?<word_en> [^•]*[^•\s]) \h* \R • \h* (?<sent_esp> [^–]*[^\s–] ) \s*–\s* (?<sent_en> .* (?:\R .*)*? ) \h* \R (?<num1> [0-9]+) \h* \| \h* (?<num2> .*\S) """# let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .allowCommentsAndWhitespace]) let testString = #""" 1 el, la art the (+m, f) • el diccionario tenía también frases útiles – the dictionary also had useful phrases 2055835 | 201481381 2 de prep of, from • es el hijo de un amigo mío – he is the son of a friend of mine 1104364 | 133341468 3 que conj that, which • dice que no quiere estudiar – he says that he doesn’t want to study 543408 | 70319525 4 y conj and • saben leer y escribir – they know how to read and write 524574 | 56511956 5 en prep in, on • vivo en el segundo piso – I live on the second floor 496295 | 49340069 6 un art a, an • era un hombre simpático – he was a nice man 381976 | 37389547 7 ser v to be (norm) • la primera persona narrativa puede ser por el protagonista – the first-person narrative can be through the protagonist 324390 | 40017214 8 a prep to, at • me voy al extranjero por el verano – I am going abroad for the summer 328540 | 48746618 9 él pron he, [ellos] them (m) • él es bastante simpático – he is very nice 428383 | 2743194 10 lo art the (+neut) • lo mejor es estudiar mucho – the best thing is to study a lot 346026 | 31016059 11 no adv no • no tiene dinero – he has no money 198473 | 21970515 +o 12 su adj his/her/their/your (–fam) • ¿Quién era? ¿Su hermana? ¿Su amiga? – Who was it? His sister? Her friend? 173372 | 17883988 13 haber v to have (+Ved) • no ha dicho nada – he hasn’t said a thing 155853 | 15650271 14 con prep with • hay un hombre con ella – there is a man with her 163958 | 18316135 15 por prep by, for, through • caminamos por el parque – we walked through the park 174450 | 17512892 16 para prep for, to, in order to • ¡Tengo una sorpresa sensacional para ti! – I have a wonderful surprise for you! 112694 | 16947562 17 mí pron me (obj prep) • el regalo era para mí – the gift was for me 114124 | 608449 +o 18 lo pron [3rd person] (dir obj-m) • lo compré en la tienda – I bought it at the store 101112 | 5126699 +o 19 tener v to have • Mi padre tiene varios relojes antiguos. – My father has several antique watches. 85865 | 11087983 +o 20 como conj like, as • ser compositor en España es como ser torero en Finlandia – being a composer in Spain is like being a bullfighter in Finland 98660 | 12480595 21 estar v to be (location, change from norm) • él está en el trabajo – he is at work 88421 | 9574000 22 me pron me (obj) • ¿Cuando me va a llamar? – When is he going to call me? 64024 | 8211349 +o 23 más adj more • él necesitaba más dinero – he needed more money 86998 | 9003898 24 este adj this (m) [esta (f)] • es igual en el este como en el oeste – it is the same in the east as in the west 73920 | 13208363 25 le pron [3rd person] (indir obj) • nunca le dijo la verdad – she never told him the truth 64833 | 7787199 26 hacer v to do, make • he podido hacer lo que me gusta – I have been able to do what I like 64199 | 8808576 27 se pron [“reflexive” marker] • el saber de los geógrafos griegos se difundió por Europa – Greek knowledge of geography spread throughout Europe 60393 | 28984360 +w 28 yo pron I (subj) • ¡Yo soy el padre! – I am the father! 45822 | 10894793 +o +w 29 o conj or • sí esperaba uno o dos muertos – yes, he expected one or two deaths 71054 | 9100644 30 pero conj but, yet, except • no significa nada para mí, pero no puedo olvidarla – it means nothing to me, but I can’t forget it 66748 | 6871867 31 decir v to tell, say • Parece que dice la verdad. – It seems like he is telling the truth. 61678 | 6016427 +o 32 poder v to be able to, can • Con estos datos se puede tener una primera idea del mecanismo. – With these facts we can begin to understand the mechanism 61177 | 9248731 33 ir v to go • ¿Quieres ir a la playa este fin de semana? – Do you want to go to the beach this weekend? 52054 | 4435468 +o 34 ese adj that (m) [esa (f)] • ¿Dónde viven esas mujeres? – Where do these women live? 48535 | 4683205 +o 35 otro adj other, another • No comparte su taxi nunca conotrosviajeros a menos que les conoce. – Don’t share your taxi with other travelers unless you know them. 54762 | 5431865 36 si conj if, whether • si quiere cazar, vamos a cazar – if he wants to hunt, let’s go hunting 38328 | 6519137 37 mi adj my • mi casa es su casa – my house is your house 34310 | 4766226 38 ver v to see • había que subir para ver las ruinas – you have to climb up to see the ruins 39015 | 4122615 39 ya adv already, still • su marido ya ha dicho todo – her husband has already said it all 37257 | 3961260 +o 40 porque conj because • lo vendo sólo porque tengo un problema muy grande – I am only selling it because I am in a predicament 34109 | 3154550 +o 41 mucho adj much, many, a lot (ADV) • por lo visto tienen mucho dinero – apparently they have a lot of money 35069 | 4459289 +o 42 dar v to give • me dio esta carta para ud – he gave me this letter for you 32999 | 3900029 +o 43 muy adv very, really • está muy contento con mi trabajo – she is very happy with my work 32854 | 3217244 +o 44 saber v to know (a fact), find out • se necesita humildad para saber reconocer las propias faltas – you need humility to know how to recognize your own faults 27238 | 2642079 +o 45 sí adv yes • quiero una respuesta concreta: sí o no – I need a solid answer: yes or no 31716 | 1100318 +o 46 año nm year • no lo supo hasta casi un año después – he didn’t find out until almost a year later 37168 | 3792004 47 ti pron you (obj prep-sg/+fam) • no, la carta no es para ti – no, the letter is not for you 29283 | 366540 +o 48 te pron you (obj/+fam) • ¿No te han hablado? – They haven’t spoken with you? 19928 | 4017417 +o 49 también adv also • también habla italiano – she speaks Italian as well 31172 | 3209504 50 qué pron what?, which?, how (+ADJ)! • no sé qué voy a hacer – I don’t know what I’m going to do 29722 | 2317175 +o 51 alguno adj some, a few • habló algunas palabras con el agente de negocios – he spoke a few words with the business agent 27224 | 3037373 52 nos pron us (obj) • nos vio en la calle – he saw us on the street 17300 | 4445709 +o +w 53 tu adj your (+fam) • ésta es tu casa y ésta es tu cama – this is your house and this is your bed 8068 | 7260841 +w 54 sin prep without • se habían quedado sin dinero – they were left without money 25332 | 2499874 55 mismo adj same • pronunciando el mismo discurso en siete idiomas – giving the same speech in seven languages 23973 | 3339470 56 eso pron that (n) • y eso no es todo – and that isn’t everything 20972 | 2339488 +o 57 cuando adv when • aquel libro es de mis nietos, cuando eran bebes todavía – that book belonged to my grandchildren, when they were still babies 32690 | 71759 58 querer v to want, love • quiero que este proceso salga con limpieza – I want this process to go cleanly 20091 | 2897092 59 vez nf time (specific occurrence); en v. de: instead of • es la primera vez que estoy junto al mar – this is the first time that I have been near to the sea 27629 | 1558559 60 hasta prep until, up to, even (ADV) • toda la noche, hasta las tres de la mañana – all night long, until three in the morning 27638 | 2258791 61 la pron [3rd person] (dir obj-f) • la puso en su bolsillo – he put it in his pocket 8190 | 7941346 +o +w 62 sobre prep on top of, over, about • dejó el papel sobre la mesa y se fue – he left the paper on top of the table and left 26590 | 3030210 63 entre prep between, among • la cosa es entre tú y yo – the matter is between you and me 32379 | 2607736 64 dos num two • la familia se reúne cada dos años – the family gets together every two years 27487 | 2017874 65 día nm day • cada día hay más problemas – every day there are more problems 20735 | 2577473 66 grande adj large, great, big • tiene los grandes ojos negros y bonitos – she has the biggest and most beautiful black eyes 29813 | 2030849 67 así adv like that • la vida es así – life is like that 21331 | 2321804 68 pasar v to pass, spend (time) • no ha pasado ni un bus – not a single bus has passed by 20946 | 1905621 69 cosa nf thing • estoy ya interesado en otra cosa – I am interested in a different matter 17977 | 1903169 +o 70 desde prep from, since • Lo habia pensado desde el principio que era una mal idea. – I thought from the beginning that this was a bad idea. 24743 | 2424665 71 deber v should, ought to; to owe • la cosa está en el lugar donde debe estar – the thing is in the place where it should be 19965 | 3248053 72 ella pron she, [ellas] them (f) • ella es muy estudiosa – she is very studious 18720 | 1491405 73 pues conj then, well then • pues, venga usted cuando quiera – well then, come whenever you want 18535 | 1210256 +o 74 entonces adv so, then • vamos entonces a cambiarlo – then we are going to change it 19759 | 888406 +o 75 llegar v to arrive • por fin llegamos al fondo de la catarata – we finally arrived at the bottom of the waterfall 18877 | 1848469 76 poco adj little, few, a little bit (adv) • trabajó poco tiempo con él – he worked a little while with him 18209 | 1845555 77 nuestro adj our • no servía para nuestro país porque somos diferentes – it was no good for our contry because we’re different 13411 | 3496070 +w 78 bien adv well • el número de bienes que pueda poseer en un momento dado – the number of goods one possesses in a given moment 16402 | 1959560 +o 79 ni conj not even, neither, nor • pero ni eso me tranquilizó – but not even that reassured me 16340 | 1927472 80 tiempo nm time (general) • ha estado mucho tiempo con ella – he has been with her a long time 18408 | 1921017 81 ahora adv now • lo importante ahora es contarte lo que le pasó – the important thing now is to tell you what happened 17072 | 1591817 +o 82 primero adj first • Primero, vamos a ir al supermercado. – First, we are going to go to the grocery store. 20758 | 2484553 83 creer v to believe, think • creo en la justicia de Dios – I believe in the justice of God 15928 | 1685972 +o 84 donde adv where • no sé donde está la llave – I don’t know where the key is 17601 | 2151872 85 vida nf life • ha dedicado toda la vida a la música – she has dedicated her life to music 15149 | 2424426 86 dejar v to let, leave • ella no dejó que yo lo olvidara – she didn’t let me forget it 14241 | 1881239 87 nada pron nothing, (not) at all • no hay nada que hacer – there is nothing to do 14024 | 1498787 +o 88 tanto adj so much, so many • no podía creer que haya tanta gente junta – I couldn’t believe there were so many people together 16618 | 1960237 89 parecer v to seem, look like • Mi burra es tan flaca parece un esqueleto. – My donkey is so thin he looks like a skeleton. 15096 | 1330117 90 hablar v to speak, talk • algunos hablan quechua, español, e inglés – some of them speak Quechua, Spanish, and English 14325 | 1432852 +o 91 poner v to put (on), get (+ADJ) • puso el cuchillo en la mano – he put the knife in his hand 14619 | 1657298 92 parte nf part, portion • el arte es una parte tan importante de la cultura – art is such an important part of culture 20938 | 1744336 93 eh interj eh • Te interesa esta bufanda, ¿eh? – You are interested in this scarf, eh? 16011 | 33653 +o 94 nuevo adj new • marcaba el comienzo de una nueva vida para mí – it marked the beginning of a new life for me 19641 | 1964400 95 sólo adv only, just • no siempre vestía ropa de mujer; sólo en carnaval – I don’t always wear women’s clothes; only during carnival 15824 | 2043480 96 siempre adv always, forever • siempre ha sido así – she has always been like that 13141 | 1671829 97 hombre nm man, mankind, husband • yo soy un hombre de pocas necesidades – I am a man of few needs 14773 | 1240825 98 bueno adv well . . . • Bueno, ¿y ahora qué hacemos? – Well, so what are we going to do now? 15729 | 1108838 +o 99 seguir v to follow, keep on • no la puedo seguir porque habla demasiado rápido – I couldn’t keep up because she was speaking so quickly 14081 | 1824937 100 quedar v to remain, stay • El aire empezó a quedarse quieto. – The air began to remain still. 14040 | 1348837 """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let substitutionString = #"\1\t\2\t\3\t\4\t\5\t\6\t"# let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString) print(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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression