Search
 
SCRIPT & CODE EXAMPLE
 

PERL

perl regex syntax

# Perl regex metacharacters:

| Symbol |         Meaning         |
|:------:|:-----------------------:|
|    .   |      any character      |
|   w   |    alphanumeric and _   |
|   W   |  any non-word character |
|   s   |      any whitespace     |
|   S   |    any non-whitespace   |
|   d   |   any digit character   |
|   D   | any non-digit character |
|   	   |           tab           |
|   
   |         newline         |
|    *   |  match 0 or more times  |
|    +   |  match 1 or more times  |
|    ?   |    match 0 or 1 times   |
|   {n}  |  match exactly n times  |
|  {n,m} |    match n to m times   |
|    ^   |     match from start    |
|    $   |       match to end      |

# Note: 
#	- use square brackets to match any of a set of characters, like [ACGT]
# 	- use ^ inside square brackets to negate matching those characters (i.e.
#		when you don't want to match any of them)
#	- use - to specify a character range, e.g. [a-d] to match any of a, b, c, d

# Example usage:
if ($dna_seq =~ m/^ATGCC[ACGT]GGN{6,9}(TAG|TGA|TAA)$/) {print "It's a match"};
# Where this will match any $dna_seq that starts with ATGCC, followed by one
#	character from ACGT, followed by GG, followed by 6-9 N characters, and
#	ending with TAG, TGA, or TAA
Comment

perl match regex

# Basic syntax:
$your_string =~ /regex pattern to match/
# Use !~ for not matching

# Example usage:
# Check if the regex pattern your is found in the variable $your_string
my $your_string = "this is your string";
if ($your_string =~ /your/) {
	print "your_string contains your
"
}
--> your_string contains your

# Check if the regex pattern y?o*u+r is found in the variable $your_string
my $your_string = "this is your string";
if ($your_string =~ /y?o*u+r/) {
	print "your_string matches pattern
"
}
--> your_string matches pattern
# Where, in regex:
# 	- ? matches 0 or 1 of the preceeding characters
#	- * matches 0 or more of the preceeding characters
#	- + matches 1 or more of the preceeding characters
Comment

PREVIOUS NEXT
Code Example
Perl :: perl while loop 
Perl :: perl for 
Perl :: print a variable perl 
Perl :: how to launch a perl script 
Perl :: perl leading zeros formatting sprintf 
Perl :: Perl (perl 2018.12) sample 
Pascal :: wait for input in pascal 
Pascal :: pascal iteration 
Pascal :: pascal area 
Powershell :: powershell remove node_modules 
Gdscript :: godot close game 
Gdscript :: gdscript dictionary 
Abap :: abap alv popup 
Erlang :: tcp server erlang 
Assembly :: regex find a word index of all matches 
Assembly :: creating a sparse-file with dd 
Assembly :: gridbaglayout span 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: list all node processes 
Javascript :: javascript radian to degree 
Javascript :: check react version terminal windows 
Javascript :: jquery only number allowed to 10 digit 
Javascript :: count number of checkboxes in html jquery 
Javascript :: javascript lowercase string 
Javascript :: regex date validation mm/dd/yyyy 
Javascript :: how to console.log formData 
Javascript :: js scroll to id 
Javascript :: sleep for 1 second 
Javascript :: jquery css add important 
Javascript :: dconf-editor install terminal 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =