The Regulator Regular Expression Tool

Tools for Working with Regular ExpressionsUnless you have been programming with regular expressions for sometime, we recommend that you first experiment with regularexpressions in a tool rather than in source code. The sample regexes inthis chapter and are plain regularexpressions that don’t contain the extra escaping that a programminglanguage (even a Unix shell) requires. You can type these regularexpressions directly into an application’s search box.explains how to mix regularexpressions into your source code. Quoting a literal regular expressionas a string makes it even harder to read, because string escaping rulescompound regex escaping rules. We leave that until. Once you understand the basics ofregular expressions, you’ll be able to see the forest through thebackslashes.The tools described in this section also provide debugging, syntaxchecking, and other feedback that you won’t get from most programmingenvironments.

  1. The Regulator Regular Expression Tool Box
  2. The Regulator Regular Expression Tools
  3. Regular Expression Online

Therefore, as you develop regular expressions in yourapplications, you may find it useful to build a complicated regularexpression in one of these tools before you plug it in to your program. RegexBuddyRegexBuddy is the most full-featured tool available at the time ofthis writing for creating, testing, and implementing regularexpressions.

It has the unique ability to emulate all the regularexpression flavors discussed in this book, and even convert among thedifferent flavors.RegexBuddy was designed and developed by Jan Goyvaerts, one ofthis book’s authors. Designing and developing RegexBuddy made Jan anexpert on regular expressions, and using RegexBuddy helped getcoauthor Steven hooked on regular expressions to the point where hepitched this book to O’Reilly. Figure 1-1. RegexBuddyIf the screenshot looks a little busy, that’sbecause we’ve arranged most of the panels side by side to show offRegexBuddy’s extensive functionality.

The Regulator Regular Expression Tool

The default view tucks all thepanels neatly into a row of tabs. You also can drag panels off to asecondary monitor.To try one of the regular expressions shown in this book, simplytype it into the edit box at the top of RegexBuddy’s window.RegexBuddy automatically applies syntax highlighting to your regularexpression, making errors and mismatched brackets obvious.The Create panel automatically builds a detailedEnglish-language analysis while you type in the regex.

Double-click onany description in the regular expression tree to edit that part ofyour regular expression. You can insert new parts to your regularexpression by hand, or by clicking the Insert Token button andselecting what you want from a menu. For instance, if you don’tremember the complicated syntax for positive lookahead, you can askRegexBuddy to insert the proper characters for you.Type or paste in some sample text on the Test panel. When theHighlight button is active, RegexBuddy automatically highlights thetext matched by the regex.Some of the buttons you’re most likely to use are. List AllDisplays a list of all matches.

ReplaceThe Replace button at the top displays a new window that lets youenter replacement text. The Replace button in the Test box thenlets you view the subject text after the replacements aremade. Split (The button on the Test panel, not the one at thetop)Treats the regular expression as a separator, and splits the subject into tokens based on wherematches are found in your subject text using your regularexpression.Click any of these buttons and select Update Automatically tomake RegexBuddy keep the results dynamically in sync as you edit yourregex or subject text.To see exactly how your regex works (or doesn’t), click on ahighlighted match or at the spot where the regex fails to match on theTest panel, and click the Debug button. RegexBuddy will switch to theDebug panel, showing the entire matching processes step by step.

Clickanywhere on the debugger’s output to see which regex token matched the text you clicked on. Clickon your regular expression to highlight that part of the regex in thedebugger.On the Use panel, select your favorite programming language.Then, select a function to instantly generate source code to implementyour regex. RegexBuddy’s source code templates are fully editable withthe built-in template editor. You can add new functions and even newlanguages, or change the provided ones.To test your regex on a larger set of data, switch to the GREPpanel to search (and replace) through any number of files andfolders.When you find a regex in source code you’re maintaining, copy itto the clipboard, including the delimiting quotes or slashes. InRegexBuddy, click the Paste button at the top and select the stringstyle of your programming language. Your regex will then appear inRegexBuddy as a plain regex, without the extra quotes and escapesneeded for string literals.

Use the Copy button at the top to create astring in the desired syntax, so you can paste it back into yoursource code.As your experience grows, you can build up a handy library ofregular expressions on the Library panel. Make sure to add a detaileddescription and a test subject when you store a regex. Regularexpressions can be cryptic, even for experts.If you really can’t figure out a regex, click on the Forum paneland then the Login button. If you’ve purchased RegexBuddy, the loginscreen appears. Click OK and you are instantly connected to theRegexBuddy user forum. Steven and Jan often hang out there.RegexBuddy runs on Windows 98, ME, 2000, XP, and Vista. ForLinux and Apple fans, RegexBuddy also runs well on VMware, Parallels,CrossOver Office, and with a few issues on WINE.

You can download afree evaluation copy of RegexBuddy at.Except for the user forum, the trial is fully functional for sevendays of actual use. Figure 1-2. RegexPalTo try one of the regular expressions shown in this book, browseto. Type the regex intothe box that says “Enter regex here.” RegexPal automatically appliessyntax highlighting to your regular expression, which immediatelyreveals any syntax errors in the regex. RegexPal is aware of thecross-browser issues that can ruin your day when dealing withJavaScript regular expressions. If certain syntax doesn’t workcorrectly in some browsers, RegexPal will highlight it as anerror.Now type or paste some sample text into the box that says “Entertest data here.” RegexPal automatically highlights the text matched byyour regex.There are no buttons to click, making RegexPal one of the mostconvenient online regular expression testers. Figure 1-3. regex.larsolavtorvik.comTo start, select the regular expression flavor you’re workingwith by clicking on the flavor’s name at the top of the page. Larsoffers PHP PCRE, PHP POSIX, and JavaScript.

PHP PCRE, the PCRE regexflavor discussed in this book, is used by PHP’s preg functions. POSIX is an old andlimited regex flavor used by PHP’s ereg functions, which are not discussed inthis book. If you select JavaScript, you’ll be working with yourbrowser’s JavaScript implementation.Type your regular expression into the Pattern field and yoursubject text into the Subject field.

A moment later, the Matchesfield displays your subject text with highlighted regex matches. TheCode field displays a single line of source code that applies yourregex to your subject text. Copying and pasting this into your codeeditor saves you the tedious job of manually converting your regexinto a string literal. Any string or array returned by the code isdisplayed in the Result field. Because Lars used Ajax technology tobuild his site, results are updated in just a few moments for allflavors. To use the tool, you have to be online, as PHP is processedon the server rather than in your browser.The second column displays a list of regex commands and regexoptions. These depend on the regex flavor.

The regex commandstypically include match, replace, and split operations. The regexoptions consist of common options such as case insensitivity, aswell as implementation-specific options. These commands and optionsare described in. Figure 1-4. NregexThe layout of the page is somewhat confusing. Enter yourregular expression into the field under the Regular Expressionlabel, and set the regex options using the checkboxes below that.Enter your subject text in the large box at the bottom, replacingthe default If I justhad $5.00 then 'she' wouldn't be so @#$!

If yoursubject is a web page, type the URL in the Load Target From URLfield, and click the Load button under that input field. If yoursubject is a file on your hard disk, click the Browse button, findthe file you want, and then click the Load button under that inputfield.Your subject text will appear duplicated in the “Matches &Replacements” field at the center of the web page, with the regexmatches highlighted. If you type something into the ReplacementString field, the result of the search-and-replace is shown instead.If your regular expression is invalid.

Appears.The regex matching is done in.NET code running on the server,so you need to be online for the site to work. If the automaticupdates are slow, perhaps because your subject text is very long,tick the Manually Evaluate Regex checkbox above the field for yourregular expression to show the Evaluate button. Click that button toupdate the “Matches & Replacements” display. Figure 1-5. RubularEnter your regular expression in the box between the twoforward slashes under “Your regular expression.” You can turn oncase insensitivity by typing an iin the small box after the second slash. Similarly, if you like,turn on the option “a dot matches a line break” by typing anm in the same box.

Im turns on both options. Though theseconventions may seem a bit user-unfriendly if you’re new to Ruby,they conform to the / regex /im syntax used to specify aregex in Ruby source code.Type or paste your subject text into the “Your test string”box, and wait a moment. A new “Match result” box appears to theright, showing your subject text with all regex matcheshighlighted. Figure 1-6. myregexp.comType your regular expression into the Regular Expression box.Use the Flags menu to set the regex options you want. Three of theoptions also have direct checkboxes.If you want to test a regex that already exists as a string inJava code, copy the whole string to the clipboard.

In themyregexp.com tester, click on the Edit menu, and then “Paste Regexfrom Java String”. In the same menu, pick “Copy Regex for JavaSource” when you’re done editing the regular expression. The Editmenu has similar commands for JavaScript and XML as well.Below the regular expression, there are four tabs that runfour different tests. FindHighlights all regular expression matches in the sampletext. These are the matches found by the Matcher.find method inJava.

MatchTests whether the regular expression matches the sampletext entirely. If it does,the whole text is highlighted.

This is what theString.matches and Matcher.matchesmethods do. SplitThe second box at the right shows the array of stringsreturned by String.split or Pattern.split whenused with your regular expression and sample text. ReplaceType in a replacement text, and the box at the right shows the text returnedby String.replaceAll or Matcher.replaceAll.You can find Sergey’s other regex testers via the links at thetop of the page at.One is a plug-in for Eclipse, and the other is a plug-in forIntelliJ IDEA. Figure 1-7. reAnimatorreAnimator’s regex syntax is very limited. It is compatiblewith all the flavors discussed in this book. Any regex you cananimate with reAnimator will work with any of this book’s flavors,but the reverse is definitely not true. This is because reAnimator’sregular expressions are regular in the mathematical sense.

Thesidebar explains thisbriefly.Start by going up to the Pattern box at the top of the pageand pressing the Edit button. Type your regular expression into thePattern field and click Set. Slowly type the subject text into theInput field.As you type in each character, colored balls will move throughthe state machine to indicate the end point reached in the statemachine by your input so far. Blue balls indicate that the statemachine accepts the input, but needs more input for a full match.Green balls indicate that the input matches the whole pattern. Noballs means the state machine can’t match the input.reAnimator will show a match only if the regular expressionmatches the whole input string, as if you had put it between‹ ^ › and ‹ $ › anchors. This is anotherproperty of expressions that are regular in the mathematicalsense.

Pulse amplitude modulation circuit pdf. Amplitude (PAM, Pulse Amplitude Modulation), in width (PWM. Pulse Width Modulation) and in. Generation of PAM signal using the integrated circuit. TELECOMMUNICATIONS.pdf Mars 2014.

The Regulator Regular Expression Tool Box

ExpressoExpresso (not to be confused with caffeine-laden espresso) isa.NET application for creating and testing regular expressions.You can download it at. The.NETframework 2.0 or later must be installed on your computer.The download is a free 60-day trial.

After the trial, you haveto register or Expresso will (mostly) stop working. Registration isfree, but requires you to give the Ultrapico folks your emailaddress.

The registration key is sent by email.Expresso displays a screen like the one shown in. The Regular Expression boxwhere you type in your regular expression is permanently visible.

Nosyntax highlighting is available. The Regex Analyzer boxautomatically builds a brief English-language analysis of yourregular expression.

The Regulator Regular Expression Tools

It too is permanently visible. Figure 1-8. ExpressoIn Design Mode, you can set matching options such as “IgnoreCase” at the bottom of the screen. Most of the screen space is takenup by a row of tabs where you can select the regular expressiontoken you want to insert. If you have two monitors or one largemonitor, click the Undock button to float the row of tabs. Then youcan build up your regular expression in the other mode (Test Mode)as well.In Test Mode, type or paste your sample text in the lower-leftcorner.

Then, click the Run Match button to get a list of allmatches in the Search Results box. No highlighting is applied to thesample text. Click on a match in the results to select that match inthe sample text.The Expression Library shows a list of sample regularexpressions and a list of recent regular expressions. Your regex isadded to that list each time you press Run Match. You can edit thelibrary through the Library menu in the main menu bar. The RegulatorThe Regulator, which you can download from, is notsafe for SCUBA diving or cooking-gas canisters; it is another.NETapplication for creating and testing regular expressions.

The latestversion requires.NET 2.0 or later. Older versions for.NET 1.x canstill be downloaded. The Regulator is open source, and no payment orregistration required.The Regulator does everything in one screen. The New Document tab iswhere you enter your regular expression. Syntax highlighting isautomatically applied, but syntax errors in your regex are not madeobvious. Right-click to select the regex token you want to insertfrom a menu. You can set regular expression options via the buttonson the main toolbar.

The icons are a bit cryptic. Wait for thetooltip to see which option you’re setting with each button. Figure 1-9. The RegulatorBelow the area for your regex and to the right, click on theInput button to display thearea for pasting in your sample text. Click the “Replacewith” button to type in the replacement text, if you want to do asearch-and-replace. Below the regex and to the left, you can see theresults of your regex operation.

Results are not updatedautomatically; you must click the Match, Replace, or Split button inthe toolbar to update the results. No highlighting is applied to theinput. Click on a match in the results to select it in the subjecttext.The Regex Analyzer panel shows a simple English-languageanalysis of your regular expression, but it is not automatic orinteractive.

To update the analysis, select Regex Analyzer in theView menu, even if it is already visible. Clicking on the analysisonly moves the text cursor. GrepThe name grep is derived from the g/re/p command that performed a regularexpression search in the Unix text editor ed, oneof the first applications to support regular expressions. This commandwas so popular that all Unix systems now have a dedicated grep utilityfor searching through files using a regular expression. If you’reusing Unix, Linux, or OS X, type mangrep into a terminal window to learn all about it.The following three tools are Windows applications that do whatgrep does, and more. Figure 1-10. PowerGREPTo run a quick regular expression search, simply select Clearin the Action menu and type your regular expression into the Searchbox on the Action panel.

Regular Expression Online

Click on a folder in the File Selectorpanel, and select “Include File or Folder” or “Include Folder andSubfolders” in the File Selector menu. Then, select Execute in theAction menu to run your search.To run a search-and-replace, select “search-and-replace” inthe “action type” drop-down list at the top-left corner of theAction panel after clearing the action. A Replace box will appearbelow the Search box. Enter your replacement text there. All theother steps are the same as for searching.PowerGREP has the unique ability to use up to three lists ofregular expressions at the same time, with any number of regularexpressions in each list. While the previous two paragraphs provideall you need to run simple searches like you can in any grep tool,unleashing PowerGREP’s full potential will take a bit of readingthrough the tool’s comprehensive documentation.PowerGREP runs on Windows 98, ME, 2000, XP, and Vista. You candownload a free evaluation copy at.Except for saving results and libraries, the trial is fullyfunctional for 15 days of actual use.

Though the trial won’t savethe results shown on the Results panel, it will modify all yourfiles for search-and-replace actions, just like the full versiondoes. Windows GrepWindows Grep isone of the oldest grep tools for Windows. Its ageshows a bit in its user interface , but it does what it sayson the tin just fine. It supports a limited regular expressionflavor called POSIX ERE. For the features that it supports, it usesthe same syntax as the flavors in this book. Windows Grep isshareware, which means you can download it for free, but payment isexpected if you want to keep it.To prepare a search, select Search in the Search menu.

Expression

Thescreen that appears differs depending on whether you’ve selectedBeginner Mode or Expert Mode in the Options menu. Beginners get astep-by-step wizard, whereas experts get a tabbed dialog.When you’ve set up the search, Windows Grep immediatelyexecutes it, presenting you with a list of files in which matcheswere found. Click once on a file to see its matches in the bottompanel, and double-click to open the file. Select “All Matches” inthe View menu to make the bottom panel show everything.To run a search-and-replace, select Replace in the Searchmenu. Figure 1-12. RegexRenamerType your regular expression into the Match box and thereplacement text into the Replace box.

Click /i to turn on case insensitivity, and/g to replace all matches in eachfilename rather than just the first. /x turns on free-spacing syntax, whichisn’t very useful, since you have only one line to type in yourregular expression.Use the tree at the left to select the folder that holds thefiles you want to rename. You can set a file mask or a regex filterin the top-right corner. This restricts the list of files to whichyour search-and-replace regex will be applied. Using one regex tofilter and another to replace is much handier than trying to do bothtasks with just one regex.

Popular Text EditorsMost modern text editors have at least basic support for regularexpressions. In the search or search-and-replace panel, you’lltypically find a checkbox to turn on regular expression mode.

Someeditors, such as EditPad Pro, also use regular expressions for variousfeatures that process text, such as syntax highlighting or class andfunction lists. The documentation with each editor explains all thesefeatures. Some popular text editors with regular expression supportinclude.

Comments are closed.