Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • 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
  • 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

/
/
gu

Test String

Substitution

Processing...

Code Generator

Generated Code

re = /([0-9]+)\s+(\w+(?:, \w+)?)\s+(\N+?)\s+(\H.+).*?\r?\n•\s+([\s\S]*?)\s+[0-9]+\s\|.*\s*/ str = '1 le det, pro the; him, her, it, them • vive la politique, vive l’amour – long live politics, long live love 89 | 2359662 2 de det, prep of, from, some, any • il ne rêve que d’argent et de plaisirs – he only dreams of money and pleasure 88 | 1665907 3 un adj, det, nm, pro a, an, one • je me suis cassé un ongle – I broke one of my fingernails 95 | 421500 4 à prep to, at, in • ils restent à l’école le plus longtemps possible – they remain at school as long as possible 93 | 557546 5 être nm,v to be; being • tout le monde veut être beau – everybody wants to be beautiful 91 | 514562 6 et conj and • et les larmes se remirent à couler – and the tears started flowing again 93 | 364443 7 en adv,prep,pro in, by • je suis retournée en Espagne en septembre – I returned to Spain in September 94 | 242952 8 avoir nm,v to have • on était six donc tu peux pas avoir une conversation – there were six of us so you can’t have a conversation 89 | 405020 9 que adv,conj,pro that, which, who, whom • c’est un soldat. mais que fait-il ici? – it’s a soldier. but what’s he doing here? 88 | 348428 10 pour prep for, in order to • elle jouait pour gagner – she played to win 93 | 151709 11 dans prep in, into, from • je reviendrai dans dix minutes – I will return in 10 minutes 93 | 161033 12 ce det,pro this, that • je ne déteste pas cet homme – I do not detest this man 87 | 307421 13 il pro he, it • allez voir s’il est blessé – go see if he is injured 86 | 251585 14 qui pro who, whom • je ne sais pas à qui m’adresser – I don’t know who to talk to 89 | 160867 15 ne adv not • nous ne faisons pas du très bon travail – we are not doing very good work 86 | 195309 16 sur adj,prep on, upon • t’avais une chance sur un million – you had one chance in a million 92 | 97798 17 se pro oneself, himself, herself, itself, themselves • avec ce traité, le Japon se rapproche des Etats-Unis – with this treaty, Japan brings itself closer to the U.S. 88 | 144707 18 pas adv, nm(pl) not, n’t; footstep • non, ne touchez pas! – no, don’t touch it! 83 | 161746 19 plus adv more, no more • il est considérablement plus jeune que moi – he’s considerably younger than I am 90 | 85987 20 pouvoir nm,v can, to be able to • tu peux jouer de la guitare électrique – you can play electric guitar 90 | 78074 21 par prep by • il s’y trouvait par hasard – he found himself there by accident 87 | 99628 22 je pro I • je suis contente de vous revoir – I am happy to see you again 73 | 227259-n 23 avec prep with • vous voulez aller au ciné avec moi? – do you want to go to a movie with me? 91 | 66056 24 tout adv,det,nadj,pro all, very • comme vous voyez, tout est propre – as you see, everything is clean 86 | 95071 25 faire nm,v to do, make • qu’est-ce qu’il fait? – what’s he doing? 85 | 99587 26 son det,nm his, her, its; sound; bran • un ami ingénieur du son m’aide pour les arrangements – a sound engineer friend of mine helped me with the arrangements 81 | 116681 27 mettre v to put, place • je peux me mettre à votre table? – may I sit at your table? 96 | 19654 28 autre det,nadj(f),pro other • il y a un autre problème – there’s another problem 91 | 40519 29 on pro one, we • on tire et on pose les questions ensuite – we shoot first and ask questions later 80 | 87982 30 mais adv,conj,intj but • je ne suis pas riche, mais je connais la vérité – I’m not rich, but I know the truth 83 | 69661 31 nous pro we, us • nous devons nous défendre nous-mêmes – we must defend ourselves 78 | 89100 32 comme adv,conj like, as • Tony et moi, on est comme des frères – Tony and I, we’re like brothers 87 | 49608 33 ou conj or • il en reste du café ou pas? – is there some coffee left or not? 86 | 49714 34 si adv,conj,nmi if, whether • aujourd’hui, notre économie va si mal – today our economy is going so poorly 87 | 46439 35 leur det,adj(f),pro them, their, theirs • l’énergie solaire assurait leur survie – solar energy assured their survival 87 | 39904 36 y adv,nmi,pro there • c’est certain qu’on va y aller – it’s for certain that we’ll be going there 83 | 55889 37 dire nm,v to say • je décrochais le téléphone sans rien dire à personne – I picked up the telephone receiver without saying anything to anyone 77 | 66657-n 38 elle pro she, her • j’étais fou amoureux. elle m’aimait bien – I was head-over-heels in love. she loved me a lot 78 | 66136 39 devoir nm,v to have to, owe; duty • je dois travailler sans la moindre entrave – I must work without the least bit of hindrance 83 | 46491 40 avant adji,adv,nm,prep before • tu vas te pencher en avant – you’re going to lean forward 94 | 14109 41 deux det,nmi two • il prend le train deux fois par semaine pour affaires – he takes the train on business twice per week 87 | 31727 42 même adj(f),adv,pro same, even, self • ils ne s’excusent même pas – they don’t even excuse themselves 85 | 37784 43 prendre v to take • elle lui prit la main – she took him by the hand 90 | 24323 44 aussi adv,conj too, also, as • je rêvais aussi de beaucoup voyager – I also dreamed of traveling a lot 88 | 26219 45 celui pro that, the one, he, him • tu es celui que je respecte le plus – you’re the one I respect the most 87 | 28015 46 donner v to give • j’aurais donné ma vie pour lui – I would have given my life for him 90 | 19581 47 bien adji,adv,nm well • tout va bien maintenant – everything’s going well now 81 | 39477 48 où adv,pro where • on ne dit pas où il vit – they aren’t saying where he lives 87 | 27126 49 fois nf(pl) time, times • lève la main une fois – raise your hand one time 92 | 15724 50 vous pro you • ici, vous avez une personnalité publique – here, you are a public personality 65 | 77127-n +s 51 encore adv again, yet • tu as encore menti à ta femme – you lied once again to your wife 89 | 19772 52 nouveau adj,nm new • il a construit une nouvelle vie ici – he made a new life for himself here 88 | 22005 53 aller nm,v to go • tu devrais aller te coucher, tu as l’air vanné – you should go to bed, you look wiped out 73 | 50452 54 cela pro that, it • cela demande de l’intégrité et du courage – that requires integrity and courage 73 | 50891-n +s 55 entre prep between • je marche entre les maisons – I’m walking between the houses 86 | 23028 56 premier det,nadj first • est-elle la première épouse, la deuxième? – is she the first wife, the second one? 84 | 27061 57 vouloir nm,v to want • tu veux faire ton chemin. c’est bien – you want to continue on your way. that’s OK 79 | 36467 58 déjà adv already • les rues étaient déjà pleines de monde – the streets were already full of people 93 | 11298 59 grand adv,nadj great, big, tall • tu es plus grand que je pensais – you’re taller than I thought 87 | 21583 60 mon det my • t’aurais pu rencontrer mon copain – you could’ve met my buddy 70 | 55084-n 61 me pro me, to me, myself • reviens me voir dans cinq ou six ans – come back to see me in five or six years 65 | 63357-n 62 moins adji(pl),adv,nm(pl),prep less • il avait moins d’excuses encore que ses complices – he had even less excuses than his accomplices did 90 | 14730 63 aucun det,adj,pro none, either, neither, not any • trop d’argent et aucun goût – too much money and no taste 93 | 9641 64 lui pro him, her • mais j’ai confiance qu’en lui – but I have confidence in him 75 | 38286 65 temps nm(pl) time • sur le plan spirituel, le temps n’existe pas – on the spiritual level, time does not exist 86 | 20420 66 très adv very • j’ai été bonne? très, très bonne – was I good? very, very good 82 | 26324 67 savoir nm,v to know • je ne savais plus quoi dire – I didn’t know what to say any more 78 | 32739 68 falloir v to take, require, need • il ne faut pas être raciste, point – there’s no need to be a racist, at all 84 | 22844 69 voir v to see • je tenais seulement à te voir pour te dire ... bonne chance – I just wanted to see you to say ... good luck 78 | 30907 70 quelque adv,adj,det some • il restera pour quelques mois – he will stay for a few months 86 | 18939 71 sans prep without • je fais plus jeune sans maquillage – I look younger without makeup 81 | 25099 72 raison nf reason • elle a raison, tu sais – she’s right, you know 92 | 9506 73 notre det our • notre ville a le sens de la communauté – our city has a sense of community 78 | 29713 74 dont pro whose, of which • on a tout ce dont tu rêvais en ville – everything you dreamed about is available in town 86 | 17841 75 non adv,nmi no, not • non, je ne peux pas parler maintenant – no, I can’t talk now 81 | 24848 76 an nm year • j’avais un an à la mort de mon père – I was one year old when my father died 82 | 22241 77 monde nm world, people • notre ultime but est de reconstruire le monde – our ultimate goal is to remake the world 87 | 15475 78 jour nm day • un jour, je retrouverais mes vrais parents – one day, I would find my real parents 86 | 17641 79 monsieur nm mister, sir, gentleman • comment allez-vous , monsieur? – how are you, sir? 67 | 45411 80 demander v to ask for • j’ai un service à vous demander – I would like to ask you to do something for me 86 | 16076 81 alors adv then, so • et alors? vous revenez quand? – so? when are you coming back ? 84 | 18443 82 après adv,prep after • il a succombé à ses blessures peu après – he shortly thereafter succumbed to his wounds 83 | 17733 83 trouver v to find • j’ai trouvé du sang. sur le siège avant – I found some blood. on the front seat 85 | 16036 84 personne nf,pro person, people, anybody, anyone, nobody • il ne parlait à personne en particulier – he was speaking to nobody in particular 84 | 16218 85 rendre v to render, return, yield, give up • je m’y rendis à 4 heures du matin – I went there at 4 o’clock in the morning 90 | 10226 86 part nf share • je voudrais vous faire part de quelques données – I want to share some data with you 91 | 8971 87 dernier nadj last • c’est le dernier endroit où vous auriez dû vous rencontrer – that’s the last place you should have met 83 | 17524 88 venir v to come • venez rencontrer les autres – come meet the others 81 | 19776 89 pendant adj,prep,nm during; pendant • où t’étais pendant tout ce temps? – where were you all of this time? 91 | 8413 90 passer v to pass • nous sommes passées devant la maison de ma grand-mère – we went past the front of my grandmother’s place 83 | 17070 91 peu adv little • un secret se dévoile peu à peu – a secret unfolds little by little 81 | 18830 92 lequel pro who, whom, which • il y a bien des points sur lesquels je voudrais faire des commentaires – there are many points on which I would like to comment 87 | 12507 93 suite nf result, follow-up, rest • deux, trois et ainsi de suite – two, three, and so on 93 | 5964 94 bon adj,adv,intj,nm good • ce n’est pas le bon moment – it’s not a good time 81 | 18375 95 comprendre v to understand • je comprends que vous soyez fâché – I understand that you’re upset 87 | 12482 96 depuis adv,prep since, for • je le connais depuis le lycée – I have known him since high school 83 | 16243 97 point adv,nm point; at all • je suis d’accord avec ce point de vue – I’m in agreement with that point of view 85 | 13938 98 ainsi adv thus • qu’est-ce qui le pousse à agir ainsi? – what drives him to act that way? 86 | 12358 99 heure nf hour • a quelle heure sont-ils partis? – at what time did they leave? 85 | 13215 100 rester v to stay • le temps qu’il te reste, trouve une solution – in the remaining time, find a solution 86 | 11942' subst = '\\1\\t\\2\\t\\3\\t\\4\\t\\5\\t\\n' result = str.gsub(re, subst) # Print the result of the substitution puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html