header

 

More links

AutoHotkey | Android | Arduino | COMM140Fractals | Grammar Checkers | Knots | A Million Dots Activity |  Processing | Processing for Scratch Users | RedBubble | Tutorials | Weather | World Time Meeting Planner | Favicon Generator.

Home > Tutorials > Regular Expressions

Regular Expressions & Perl Script

According to the Wikipedia:

A regular expression is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns.

For a set of useful looking tools see http://global-search-and-replace.qarchive.org/

One of the most powerful features of Regular Expressions is Negative lookahead used to match something not followed by something else.

 

Some text editors that can use regular expressions include:

Editor URL Comments
EditPad Pro Home page

http://www.editpadpro.com/download.html

EditPad Pro's regex flavor is almost identical to the one used in Perl 5. Only the extensions that only make sense in a programming language are not available. All regex operators explained in the tutorial on this website are available in EditPad Pro.

EditPad Pro integrates with RegexBuddy. You can instantly fire up RegexBuddy to edit the regex you want to use in EditPad Pro, or select one from a RegexBuddy library.

jEdit http://www.jedit.org/ GNU General Public License.
Note Tab Pro http://www.notetab.com/ Very powerful disk wide search and replace feature
Text Pad http://www.textpad.com/ Nice clean interface. Not able to search for regular expressions within files see WildEdit or Note Tab if you want to do a global search and replace on a set of files.
WildEdit http://www.textpad.com/products/wildedit

I have yet to use this tool but it sounds like it does a similar job to the Note Tab Pro

An interactive tool for power users to edit a set of text files in a folder hierarchy, filtered by wildcards. This makes it ideal for editing web pages and software source code, or reformatting log files and newsletters.

EngInSite Perl Editor Lite (2,77 MB) - Free!

http://www.enginsite.com/Download.htm

http://luckasoft.com/download/perle_le.exe

 

The following is a list regular expressions that I have used

Search Replace Examples Use
<a name="(.*)">   <a name="XSLTpbhabcabcbbcabca">
<a name="a-b-a-d-">
To match anchor tags in a HTML document
<a name=".*">\n.*</a>\n  

<a name="a-b-a-d-">
       </a>

match anchor tag with closing <\a> on following line

<td(.*)>   <td style="padding: 0in 5.4pt; width: 144.65pt;" valign="top" width="241">
to match style tags used in tables
^(.) $1)

Used when converting Word documents to Aiken format

Change the following list:

A Moodle
B ATutor
C Claroline

into this:


A) Moodle
B) ATutor
C) Claroline

B\) =(.*)\r\n(.*)\r\n(.*)\r\n(.*)\r\n B) =$1\r\n$2\r\n$3\r\n$4\r\nANSWER: B

 

 

An eviscerated bowel should be managed by:
A) ~Packing with sterile cotton swabs
B) =Covering with sterile gauze (moistended with saline) and cling wrap
C) ~Covering with dry sterile pads
D) ~Covered using a large roller bandage

 

Assist with converting from GIFT to Aiken format quetions

 

 

Perl Script

Expression Examples Comments
perl -0777 -pi -e 's/<\/?FONT[^>]*>//gi' filename
   
# remove font tags
s/<\/?FONT[^>]*>//gi;

Replaces this :

<font size=2>Hi there. <b>Hey! I'm bold!</b> Plain again.</font>

With this :

Hi there. <b>Hey! I'm bold!</b> Plain again.

Thanks to

Anthony Boyd,
Per M Knutsen,
and
mike gifford

faqts.com

Perl Cheat Sheet Includes:

Functions, Comparison Operators,Regular Expressions, Variable and Special Variables and Command-line options


https://www.pcwdld.com/perl-cheat-sheet

A Perl function is a group of statements used to perform a specific task. It allows users to divide their code into separate parts to reuse the code defined in the function.

Perl comes with a wide range of command-line options that can be used to turn on or turn off different behaviors. You can create one-off command-line scripts to make your programs more concise.

 

Note Tab Expressions

See ClipWriter http://www.dataomega.com/ClipWriter/

Expression Examples Use
^!Replace "(^\w\w)\w* (\w*)" >> $1$2 RWAS

Replace:

Sarah Kelly
Stephen Dinnell
Tegan Bell

With:

SaKelly
StDinnell
TeBell

To make user names from full names

 

 

 

Regular Expression Links

 

Perl Links

Perl Ports (Binary Distributions)

Perl Documentation

Web-Wise-Wizard - Perl Regular Expressions Perl regular expression examples. Learn regular expressions the easy way. Examples include methods to manipulate strings and for HTML page parsing. Use these examples to harness the power of Regex.
 

Perl regular expression examples

 

Books


APA citation:
Russell, R. (2023, January 25, 08:43 am). REgular expressions.
     Retrieved April 24, 2024, from http://www.rupert.id.au/tutorials/regular-expressions/index.php

Last refreshed: April 24 2024. 02:44.02 pm

rupert dot russell at acu dot edu dot au Support Wikipedia

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.


879 visits since July 26, 2006