Regular Expressions 101

Save & Share

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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/([ぁ-ヿ、]+)\n(.+)\n\n/'; $str = '割れる(われる) to break, to be smashed; to split, to crack, to fissure, to be torn; to be divided (opinion, vote, etc.), to split (e.g. of a party); to come to light, to become clear, to be identified, to be revealed; to be distorted (of a sound); to be divisible (without a remainder); to go below a minimum 話す(はなす) to talk, to speak, to converse, to chat; to tell, to explain, to narrate, to mention, to describe, to discuss; to speak (a language) 燃える(もえる) to burn, to get fired up 辞書(じしょ) dictionary, lexicon; letter of resignation なので because, as, since なのに and yet, despite this, but even so, but even then, however, nevertheless, for all that, notwithstanding that 働く(はたらく) to work, to labor, to labour; to function, to operate, to be effective, to work (i.e. ... works), to come into play; to commit (e.g. a crime), to perpetrate, to do, to act, to practise, to practice; to be conjugated 動く(うごく) to move, to stir, to shift, to shake, to swing; to operate, to run, to go, to work; to make a move, to take action, to act, to go into action; to be touched, to be influenced; to change, to vary, to fluctuate, to waver; to be transferred 吊る(つる) to hang, to suspend, to sling, to wear (e.g. a sword), to put up (e.g. a shelf); to hang oneself; to hoist an opponent off of his feet by his loincloth; to turn upwards (as if being pulled), to be slanted (of eyes); to pucker (e.g. of a seam), to be pulled tight 必ず(かならず) always, without exception, necessarily, certainly, without fail, positively, invariably 気づく(きづく) to notice, to recognize, to recognise, to become aware of, to perceive, to realize, to realise 校訓(こうくん) school precepts 進捗(しんちょく) progress, being under way 助かる(たすかる) to be saved, to be rescued, to survive; to escape harm, to be spared damage; to be helped, to be saved trouble 補助(ほじょ) assistance, support, aid, help; subsidy, supplement, subvention, grant-in-aid; auxiliary, subsidiary; spot (in bodybuilding) 助言(じょげん) advice, suggestion 外注(がいちゅう) outside order, outsourcing, custom (manufacture) 返却(へんきゃく) return of something, repayment 発言(はつげん) statement, remark, observation, utterance, speech, proposal 十人十色(じゅうにんといろ) several men, several minds, everyone has his own ideas and tastes, everyone has his own interests and ideas, different strokes for different folks 理由(りゆう) reason, pretext, motive 自宅(じたく) one\'s home, one\'s house 在宅勤務(ざいたくきんむ) working at home, telecommuting 残業(ざんぎょう) overtime (work) 天狗(てんぐ) tengu, long-nosed goblin; bragging, conceit, braggart, boaster, conceited person 南京錠(ナンキンじょう) padlock 錠剤(じょうざい) pill, lozenge, tablet 悪魔(あくま) devil, demon, fiend; Satan, the Devil; Māra, evil spirits or forces that hinder one\'s path to enlightenment 紙ばさみ(かみばさみ) paper holder, paper clip 潜水艦(せんすいかん) submarine 消火栓(しょうかせん) fire hydrant 地球儀(ちきゅうぎ) globe (map) 三つ葉のクローバー(みつばのクローバー) three-leaf clover 工場(こうじょう) factory, plant, mill, workshop トイレットペーパー toilet paper 蛇口(じゃぐち) faucet, tap 説明(せつめい) explanation, exposition 解説(かいせつ) explanation, commentary, exposition, elucidation 説得(せっとく) persuasion まず first (of all), firstly, to start with, above all; probably, almost (certainly), hardly, practically, more or less; anyway, at any rate, for now (at least), for the time being 次(つぎ、つぐ、ジ) next, order, sequence 最後(さいご) end, conclusion; last, final, latest, most recent; no sooner than, once, right after (often having negative consequences); one\'s final moments ツイート tweet, Twitter post ボール ball; ball (pitch that falls outside of the strike zone); bowl; board (cardboard, pasteboard, etc.) 雪だるま(ゆきだるま) snowman テント tent 看病人(かんびょうにん) nurse スパナ spanner, wrench 恐竜(きょうりゅう) dinosaur ゴルフ golf 砂時計(すなどけい) hourglass 弟子(でし) pupil, disciple, adherent, follower, apprentice, young person, teacher\'s student-helper ショッピングカート shopping cart 熱気球(ねつききゅう) hot-air balloon 水桶(みずおけ) pail (for water), bucket; cistern, water tank 賞杯(しょうはい) trophy, prize cup トロフィー trophy 並ぶ(ならぶ) to line up, to stand in a line; to rival, to match, to equal 困る(こまる) to be troubled, to have difficulty, to be in a fix, to be at a loss, to be stumped, to be embarrassed; to be bothered, to be inconvenienced, to be annoyed; to be badly off, to be hard up, to be in straitened circumstances 確認(かくにん) confirmation, verification, validation, review, check, affirmation, identification 早退(そうたい) leaving early 送る(おくる) to send (a thing), to dispatch, to despatch, to transmit; to take or escort (a person somewhere), to see off (a person); to bid farewell (to the departed), to bury; to spend (time), to live one\'s life; to pass (down the line); to affix okurigana 書類(しょるい) document, official papers とのこと I\'m told, is what I heard, is how it is, apparently, is what they said 撮影(さつえい) photography (still or motion), photographing, filming, shooting, (video) recording 優先順位(ゆうせんじゅんい) priority, order of precedence 必要(ひつよう) necessary, needed, essential, indispensable; necessity, need, requirement 気が抜ける(きがぬける) to lose heart, to lose interest, to lose motivation, to be discouraged; to become stale (i.e. of a carbonated beverage), to go flat, to lose flavor, to lose flavour, to be exhausted, to feel spent 出身(しゅっしん) person\'s origin (e.g. city, country, parentage, school) 弄ぶ(もてあそぶ) to play with (a toy, one\'s hair, etc.), to fiddle with; to toy with (one\'s emotions, etc.), to trifle with; to do with something as one pleases; to appreciate 聖(セイ、ひじり、ショウ) holy, saint, sage, master, priest Created with Japanese for iOS® '; $subst = "$1\t$1\t$2\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