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 until loop 
Perl :: perl remove all whitespace 
Perl :: perl hash ref create 
Perl :: perl split array into smaller arrays 
Perl :: difference between @ and $ in perl 
Perl :: Perl - Common Conditional Statements 
Pascal :: pascal pause until key is pressed 
Pascal :: pascal delay 
Pascal :: Pascal (fpc 3.0.4) sample 
Powershell :: powershell -executionpolicy bypass -file 
Powershell :: To look at a profile to see information about a wifi network 
Gdscript :: GDScript typed variables 
Abap :: abap integer 
Erlang :: tcp client erlang 
Assembly :: vba hello world 
Assembly :: Discord bot name of person being tagged 
Assembly :: dd utility seek 
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
1+2 =