Regular Expressions 101

Save & Share

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

/
/
mgi

Test String

Code Generator

Generated Code

import Foundation let pattern = ##"(\S*\$|\%|\&\S*)|(\S*\#.*?\s|\{.*?\}|\=\(\S*)|(\S*\w*\:\))"## let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive]) let testString = ##"<h6>O'GRADY, T.:02Aug2016 at 04:17:06:</h6> getting defect setup <h6>O'GRADY, T.:22Aug2016 at 10:23:02:</h6> JA only. ZH does not localize JSG <h6>O'GRADY, T.:30Nov2016 at 16:55:23:</h6> thanks Sheila From: Sheila Loring Sent: Wednesday, November 30, 2016 4:52 PM To: Chris Swift &lt;Chris.Swift@jmp.com&gt; Cc: Trish O'Grady &lt;Trish.O'Grady@jmp.com&gt; Subject: JSG Chris, the JSG and images/scripts are ready for translation. <h6>SWIFT, CHRISTOPHER:01Dec2016 at 13:23:34:</h6> Hello Chris, JSG source files downloaded. Thank you very much!! Anja Anja Belhazy Senior Project Manager (408) 453-6303 x 31 HighTech Passport Internationalization and Localization 1590 Oakland Rd #B202, San Jose CA 95131 www.htpassport.com Chris Swift wrote: Hi Anja, I have pushed the source materials for JSG to your FTP site in /ToHTP... ? HTP-Commit-20161130A-JSG.zip This represents the latest document source files and images. Please confirm receipt. Thanks, Christopher Swift <a href="http://www.sas.com">http://www.sas.com</a> SAS(r) ... THE POWER TO KNOW(r) <h6>O'GRADY, T.:05Dec2016 at 09:40:56:</h6> changed support back to trish <h6>LIU, HONGMEI:28Feb2017 at 01:41:25:</h6> The ja screenshots has been pushed into \Dept\JMPl10n\Components\Doc\JSG\ja\images::13.0 The following things please get to know 1. the script is missing for the image \BuildingApplications\appbuilder_iris.png 2. many English strings appears on a lot of images under the folder Display and Graphics, because the strings are customizable in the script. If the reviewer wants them to be localized, the texts in the script should be translated first. We can retake. <h6>LORING, SHEILA:28Feb2017 at 10:30:55:</h6> I'm working on #1 and #2. <h6>LORING, SHEILA:28Feb2017 at 17:12:25:</h6> #1. I've checked in JSG/Images/BuildingApplications/appbuilder_iris.jmpappsource and appbuilder_iris.jsl. #2. I've added "//dtp:translate" to scripts in Graphics and Displays where necessary. <h6>LIU, HONGMEI:02Mar2017 at 01:27:52:</h6> Thank you Sheila Could please sync the scripts with Prism? Thanks <h6>O'GRADY, T.:02Mar2017 at 10:09:51:</h6> Victoria or Chris / can you please sync changes to PRISM? Hongmei - I will ask the team in JMP Japan to translate the scripts and will provide to you. Thanks <h6>O'GRADY, T.:02Mar2017 at 12:04:53:</h6> LOCALIZATION TEAM Please hold on putting anything into PRISM until you hear back from me. <h6>O'GRADY, T.:02Mar2017 at 13:38:04:</h6> L10N/DOC TEAM Sheila will push files to 13.2 track and update this defect with push information. Localization team can get the files from 13.2 and push to PRISM. HONGMEI I still need to get some scripts localized for you. For some of the scripts, it looks like the only change was that the doc team added DTP notes or dtp:translate into the script and then reshot as .png (rather than leaving it as a .gif). So we will need to retake as well to get the new format. <h6>SWIFT, CHRISTOPHER:02Mar2017 at 13:47:17:</h6> Hi Hongmei, Trish asked me to provide you with an installer from December 27th, 2016 for images. You should be able to find this installer on the network, but I have also pushed to our FTP site. ftp://defrko:jmp6loc@ftp.jmp.com/fromJMP/JMPPro-Installer-20161227.zip And is also available on the network... \\jmpsrv01\dev\install\JMP13\JMP1310\WinOS\JMPPRO\2016.12.27 Please confirm receipt! Thanks, Chris <h6>LORING, SHEILA:02Mar2017 at 13:48:58:</h6> I have pushed the updated scripts to 13.2. <h6>O'GRADY, T.:21Mar2017 at 09:50:23:</h6> Chris - can you push to PRISM? Note that this is coming from 13.2 not main. <h6>O'GRADY, T.:21Mar2017 at 13:15:47:</h6> I have provided screenshots to HTP. I gave them EN and JA images for V12 as well as V13. For V13I grabbed EN images from P4 from here: //depot/rel/r13.2/docsource/BookMaster/JSG/Images/ This is what will go into PRISM when Chris pushes. We have some .jsl scripts that need to be localized before screenshots can be retaken. I'm going to ask HTP to localize .jsl scripts and retake screenshots that need to be retaken. Screenshots for JSG are tricky. I'll update the defect once we have sorted all this out. <h6>O'GRADY, T.:28Mar2017 at 11:49:46:</h6> HTP will use the EN source that I handed off on 27March2017 in this .zip file: JSG_19Dec2016_sourceToHTP.zip which lives in \\jmpsrv01\source\XLator\Staging\13.2 Support changed to Victoria ****VICTORIA**** Can you please push these EN .FM files in the .zip file referenced above into PRISM? Note that you are only pushing .FM files. We do not have the .mif files for these .FM files. (for reference/the "why" see <a href="http://sww.sas.com/ds/DefectsSearch/S1316/S1316722.html">S1316722</a> "ListOfFilesAndNextSteps.docx) That's OK! The EN images that are currently in PRISM match the .FM files that you are going to put into PRISM. Please change support back to Trish when you have pushed the files. <h6>O'GRADY, T.:19Jul2017 at 09:39:01:</h6> Marking this fixed for 13.2 Chris pushed Scripting Guide.pdf to P4 on 14July2017 changelist 244258 <a href="http://sww.sas.com/ds/DefectsSearch/S1281/S1281721.html">S1281721</a> Final JA PDFs 13.2 JA PDF is in P4. (JA is the only language that localizes this book) Opening in V14 track. Verified - compared PDF in P4 with PDF in PRISM. They match. <h6>O'GRADY, T.:23Mar2018 at 14:21:13:</h6> added date for ja screenshots 18june2018. Zh does not localize this book. <h6>O'GRADY, T.:03Apr2018 at 15:31:59:</h6> screenshot comps for JA JSG are complete. Uploaded to this DEFECT is docimages-JSG-JA-PRISM-13.0-VERSUS-JA-Prism-14.0-20180401T095914.xls Melanies documentation for JA JSG can be found here: <a href="http://sww.sas.com/jmpmediawiki/L10N_Big_Books_Project_JMP_14#Images_for_JSG_for_Japanese">http://sww.sas.com/jmpmediawiki/L10N_Big_Books_Project_JMP_14#Images_for_JSG_for _Japanese</a> ZH doc not localize this book. <h6>LIU, HONGMEI:24May2018 at 05:33:18:</h6> The ja images has been pushed. \Dept\JMPl10n\Components\Doc\JSG\ja\images::14.0 There're some issues. Could you help? 1. Extending\RESTdatatable_NoLoc.png There is an error "HTTP/1.1 500 Internal Server Error" appears after running the script. We applied the key, does this matter? 2. ProgrammingFunctions\cmd.png The text shows in garbage. <h6>LORING, SHEILA:24May2018 at 12:49:26:</h6> Hi, Hongmei. 1. I'm a little confused about why you're retaking the RESTdatatable_NoLoc.png screenshot. The data in the database being queried is in English, so you'll end up with the same screenshot that we sent you. 2. Would you send a screenshot of the garbage you're seeing? Also, if you press Ctrl+Alt+Delete and select Task Manager, do you see a window that lists all of the running tasks? <h6>O'GRADY, T.:24May2018 at 15:15:03:</h6> Support to Sheila. Can you please check into the two issues that Hongmei is having? <h6>LIU, HONGMEI:28May2018 at 02:46:36:</h6> Hi Sheila, 1. the screenshot RESTdatatable_NoLoc.png needs to be recaptured because the menus have been localized. After running the script in the log window an error showed. The table window had no dada but just column 1. 2. I attached a screenshot for your reference, also include the running result of 1. <h6>LORING, SHEILA:29May2018 at 11:37:23:</h6> 1. I don't know why the database is giving you an error. My suggestion is to crop out the menu bar so you can use the English screenshot. 2. I don't know what's causing the garbled characters on your screen and don't know how to troubleshoot it other than to reboot. Can you try taking it on another computer? <h6>LIU, HONGMEI:30May2018 at 04:08:50:</h6> 1. this screenshot has been captured and pushed into prism 2. I tried on Win10/Win7 many different computers, but the output was same...I contacted the tester in Beijing and was told it seemed to be related with the defect <a href="http://sww.sas.com/ds/DefectsSearch/S1168/S1168665.html">http://sww.sas.com/ds/DefectsSearch/S1168/S1168665.html</a> I'd updated the images (cmd.png and RESTdatatable_NoLoc.png) on Prism so that they can be used in doc. If you have any different thinking of them please let me know. Trish, i'd also like to let you know that there're some English strings that come from input in script. if you want them to be localized please let me know i'll retake...I list them here: CommonTasks\ExtractValues_NoLoc.png DataTables\FormulaEditor_CustomFunction.png Displays\ColoredText.png Displays\ConfidenceLimits.png Graphics\LineStyles_NoLoc.png ThreeDimensions\TextEx_NoLoc.png <h6>O'GRADY, T.:30May2018 at 15:41:10:</h6> Thanks Hongmei, I will check into this. <h6>O'GRADY, T.:15Jun2018 at 11:44:52:</h6> I checked with Sheila on this. Most of the images above would not be localized. Sheila will update their name to "NoLoc" for V15. I'm checking with the JA team on this image. DataTables\FormulaEditor_CustomFunction.png I've asked them to provide the translations to be if they would like the text on the screenshot localized. I should have that on 18June and will update this defect with info. Goal date for final JA screenshots moved from 18June to 19June2018. <h6>O'GRADY, T.:18Jun2018 at 06:23:57:</h6> p4 edit //depot/main/docsource/BookMaster/JSG/Images/DataTables/FormulaEditor_CustomFunc tion.jsl 1 file opened for edit p4 submit -f submitunchanged -i Submitted change 289208 1 file edited Kyoko-san provided the translation for one line of code for FormulaEditor_CustomFunctions. All other lines should remain in English. Support back to Hongmei <h6>O'GRADY, T.:21Jun2018 at 11:44:57:</h6> Hongmei I updated DataTables/FormulaEditor_CustomFunction.jsl in PRISM. The translated line of code is in the script. Can you please retake the screenshot? Please note. You are going to have to remove a file from your machine before you can take this screenshot. Please delete JMPFormulaEditorFunctions.PFS in this folder ==&gt; C:\Users\saspro\AppData\Roaming\SAS\JMP\14 If you do not delete this file, you will see the English string "Number Stuff" and that Japanese translation of "Number Stuff" <h6>LIU, HONGMEI:21Jun2018 at 23:18:37:</h6> The image DataTables/FormulaEditor_CustomFunction has been retaken. \Dept\JMPl10n\Components\Doc\JSG\ja\images\DataTables::14.0 <h6>O'GRADY, T.:22Jun2018 at 12:28:50:</h6> Thank you very much Hongmei. Screenshots delivered to HTP. Our copy of the .zip stored in here. \\jmpsrv01\source\XLator\Staging\14.1\JSG_JAScreenshotsToHTP22June2018.zip Closing this for V14; opening in 15.0; support over to trish <h6>CONNERS, SHANNON:25Jun2018 at 15:10:59:</h6> Changing pubs affected to N for open defects for JMP.LOCALIZATION. <h6>O'GRADY, T.:04Oct2018 at 08:58:19:</h6> JA for 14.2 final and pushed to P4 c:\JMPMain\depot\rel\r14.2\product\doc\Portable\Japanese\Scripting Guide.pdf 1 file opened for add p4 submit -f submitunchanged -i Submitted change 309969 1 file added <h6>WANG, TING:10Dec2019 at 20:44:00:</h6> <h6>O'GRADY, T.:22Jan2020 at 07:57:33:</h6> ja screenshots can be taken. Support to Hongmei <h6>LIU, HONGMEI:17Feb2020 at 01:56:34:</h6> The ja images has been pushed into P4 at //depot/main/l10nsource/BookMaster/JSG/ja/1/target/images/ <h6>O'GRADY, T.:17Feb2020 at 07:56:22:</h6> Thank you Hongmei. I delivered screenshots to JA vendor today. Marking this DEFECT fixed for 15.2; open in 16.0 <h6>O'GRADY, T.:03Jun2020 at 07:19:45:</h6> Opening in the 15.2 track - I need to push localized files from the vendor into P4. S1282028 Doc toolkit Tracking L10N: JSG / pushing .fm and .pdf / prelim translations (not reviewed yet). Angelita will push .mif files when she processes kit in memoQ.c:\JMPMain\depot\main\l10nsource\BookMaster\JSG\ja\1\target\dtp\fm\JSG.boo k c:\JMPMain\depot\main\l10nsource\BookMaster\JSG\ja\1\target\dtp\fm\JSGIX.fm {23 more items} 25 files opened for edit p4 edit c:\JMPMain\depot\main\l10nsource\BookMaster\JSG\ja\1\target\dtp\pdf\Scripting Guide.pdf 1 file opened for edit p4 revert -a //depot/main/l10nsource/BookMaster/JSG/ja/1/target/dtp/fm/JSG.book //depot/main/l10nsource/BookMaster/JSG/ja/1/target/dtp/fm/JSG_About.fm {24 more items} 1 file reverted p4 submit --parallel=0 -f submitunchanged -i Submitted change 458009 25 files edited NO Action needed from Hongmei - <h6>O'GRADY, T.:18Jun2020 at 08:38:46:</h6> pushing JSG_Tech_Notices.fm (still prelim translations). Delete JSGIX.fm Submitted change 461435 1 file added 1 file deleted <h6>O'GRADY, T.:07Aug2020 at 08:53:04:</h6> added 15.2 review files (.jsl, .rtf, .xlsx) that Kyoko-san returned. we do not have the final files .mif/.fm back from HTP yet. Submitted change 473297 26 files added <h6>DRAKE, M.:27Aug2020 at 14:24:55:</h6> Add final JA PDF Change 478274 by medrak@medrak-Win on 2020/08/27 14:24:17 S1282028 Doc toolkit Tracking L10N: JSG / JA / add final PDF Affected files ... ... //depot/main/l10nsource/BookMaster/JSG/ja/1/target/dtp/pdf/Scripting Guide.pdf#3 edit <h6>LORING, SHEILA:13Dec2020 at 15:41:29:</h6> Closed for 15.2."## let stringRange = NSRange(location: 0, length: testString.utf16.count) let matches = regex.matches(in: testString, range: stringRange) var result: [[String]] = [] for match in matches { var groups: [String] = [] for rangeIndex in 1 ..< match.numberOfRanges { let nsRange = match.range(at: rangeIndex) guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue } let string = (testString as NSString).substring(with: nsRange) groups.append(string) } if !groups.isEmpty { result.append(groups) } } 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