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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "([ぁ-ヿ、]+)\\n(.+)\\n\\n"; final String string = "割れる(われる)\n" + "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\n\n" + "話す(はなす)\n" + "to talk, to speak, to converse, to chat; to tell, to explain, to narrate, to mention, to describe, to discuss; to speak (a language)\n\n" + "燃える(もえる)\n" + "to burn, to get fired up\n\n" + "辞書(じしょ)\n" + "dictionary, lexicon; letter of resignation\n\n" + "なので\n" + "because, as, since\n\n" + "なのに\n" + "and yet, despite this, but even so, but even then, however, nevertheless, for all that, notwithstanding that\n\n" + "働く(はたらく)\n" + "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\n\n" + "動く(うごく)\n" + "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\n\n" + "吊る(つる)\n" + "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\n\n" + "必ず(かならず)\n" + "always, without exception, necessarily, certainly, without fail, positively, invariably\n\n" + "気づく(きづく)\n" + "to notice, to recognize, to recognise, to become aware of, to perceive, to realize, to realise\n\n" + "校訓(こうくん)\n" + "school precepts\n\n" + "進捗(しんちょく)\n" + "progress, being under way\n\n" + "助かる(たすかる)\n" + "to be saved, to be rescued, to survive; to escape harm, to be spared damage; to be helped, to be saved trouble\n\n" + "補助(ほじょ)\n" + "assistance, support, aid, help; subsidy, supplement, subvention, grant-in-aid; auxiliary, subsidiary; spot (in bodybuilding)\n\n" + "助言(じょげん)\n" + "advice, suggestion\n\n" + "外注(がいちゅう)\n" + "outside order, outsourcing, custom (manufacture)\n\n" + "返却(へんきゃく)\n" + "return of something, repayment\n\n" + "発言(はつげん)\n" + "statement, remark, observation, utterance, speech, proposal\n\n" + "十人十色(じゅうにんといろ)\n" + "several men, several minds, everyone has his own ideas and tastes, everyone has his own interests and ideas, different strokes for different folks\n\n" + "理由(りゆう)\n" + "reason, pretext, motive\n\n" + "自宅(じたく)\n" + "one's home, one's house\n\n" + "在宅勤務(ざいたくきんむ)\n" + "working at home, telecommuting\n\n" + "残業(ざんぎょう)\n" + "overtime (work)\n\n" + "天狗(てんぐ)\n" + "tengu, long-nosed goblin; bragging, conceit, braggart, boaster, conceited person\n\n" + "南京錠(ナンキンじょう)\n" + "padlock\n\n" + "錠剤(じょうざい)\n" + "pill, lozenge, tablet\n\n" + "悪魔(あくま)\n" + "devil, demon, fiend; Satan, the Devil; Māra, evil spirits or forces that hinder one's path to enlightenment\n\n" + "紙ばさみ(かみばさみ)\n" + "paper holder, paper clip\n\n" + "潜水艦(せんすいかん)\n" + "submarine\n\n" + "消火栓(しょうかせん)\n" + "fire hydrant\n\n" + "地球儀(ちきゅうぎ)\n" + "globe (map)\n\n" + "三つ葉のクローバー(みつばのクローバー)\n" + "three-leaf clover\n\n" + "工場(こうじょう)\n" + "factory, plant, mill, workshop\n\n" + "トイレットペーパー\n" + "toilet paper\n\n" + "蛇口(じゃぐち)\n" + "faucet, tap\n\n" + "説明(せつめい)\n" + "explanation, exposition\n\n" + "解説(かいせつ)\n" + "explanation, commentary, exposition, elucidation\n\n" + "説得(せっとく)\n" + "persuasion\n\n" + "まず\n" + "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\n\n" + "次(つぎ、つぐ、ジ)\n" + "next, order, sequence\n\n" + "最後(さいご)\n" + "end, conclusion; last, final, latest, most recent; no sooner than, once, right after (often having negative consequences); one's final moments\n\n" + "ツイート\n" + "tweet, Twitter post\n\n" + "ボール\n" + "ball; ball (pitch that falls outside of the strike zone); bowl; board (cardboard, pasteboard, etc.)\n\n" + "雪だるま(ゆきだるま)\n" + "snowman\n\n" + "テント\n" + "tent\n\n" + "看病人(かんびょうにん)\n" + "nurse\n\n" + "スパナ\n" + "spanner, wrench\n\n" + "恐竜(きょうりゅう)\n" + "dinosaur\n\n" + "ゴルフ\n" + "golf\n\n" + "砂時計(すなどけい)\n" + "hourglass\n\n" + "弟子(でし)\n" + "pupil, disciple, adherent, follower, apprentice, young person, teacher's student-helper\n\n" + "ショッピングカート\n" + "shopping cart\n\n" + "熱気球(ねつききゅう)\n" + "hot-air balloon\n\n" + "水桶(みずおけ)\n" + "pail (for water), bucket; cistern, water tank\n\n" + "賞杯(しょうはい)\n" + "trophy, prize cup\n\n" + "トロフィー\n" + "trophy\n\n" + "並ぶ(ならぶ)\n" + "to line up, to stand in a line; to rival, to match, to equal\n\n" + "困る(こまる)\n" + "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\n\n" + "確認(かくにん)\n" + "confirmation, verification, validation, review, check, affirmation, identification\n\n" + "早退(そうたい)\n" + "leaving early\n\n" + "送る(おくる)\n" + "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\n\n" + "書類(しょるい)\n" + "document, official papers\n\n" + "とのこと\n" + "I'm told, is what I heard, is how it is, apparently, is what they said\n\n" + "撮影(さつえい)\n" + "photography (still or motion), photographing, filming, shooting, (video) recording\n\n" + "優先順位(ゆうせんじゅんい)\n" + "priority, order of precedence\n\n" + "必要(ひつよう)\n" + "necessary, needed, essential, indispensable; necessity, need, requirement\n\n" + "気が抜ける(きがぬける)\n" + "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\n\n" + "出身(しゅっしん)\n" + "person's origin (e.g. city, country, parentage, school)\n\n" + "弄ぶ(もてあそぶ)\n" + "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\n\n" + "聖(セイ、ひじり、ショウ)\n" + "holy, saint, sage, master, priest\n\n\n\n" + "Created with Japanese for iOS®\n\n"; final String subst = "$1\\t$1\\t$2\\n"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("Substitution result: " + 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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html