String And Regular Expression Language Reference Page 2

ADVERTISEMENT

String & Regular Expression Language Reference
PHP
Ruby
Javascript
Python
Java
search
str
pos(s,q)
s.
index(q)
s.
indexOf(q)
s.
find(q)
s.
indexOf(q)
r
r
last
r
last
FALSE on failure
nil on failure
-1 on failure
-1 on failure
-1 on failure
s=~r; s.
index(r)
s.search(r)
s.
index(q)
r
r
nil on failure
-1 on failure
ValueError on failure
match
preg_match(q,s)
r=Regexp.compile(q)
r.test(s)
r=re.compile(q)
r=Pattern.compile(q)
returns whether there is a
tests for a (next) match
s[r]
the entire first match
m=re.search(q,s);
m=r.matcher(s)
match: 0 (failure) or 1, or
s.match(r)
match
th
s[r,i]
the i
group
m=r.search(s,i=0)
s.matches(q);
FALSE on error
result; null on failure
the first match of the
m=s.match(r);
m.matches()
preg_match(q,s,&m)
s.match(r)[i]
pattern at or after
checks for a match
m=s.match(s)
m is the destination array for
th
the i
matched group, if r
position i (default: 0) in
m.find()
match result; nil on failure
matched strings, indexed by
is local, or the i
th
matched
s. None on failure.
advances to the next match,
group
m[i]
substring if r is global
m=re.match(q,s);
returning true if a next match
preg_match_all(q,s,
th
substring matched by the i
s.match(r).index
m=r.match(s,i=0)
was found and false otherwise
group (nil if that group is
&m,f)
match offset, if r is local
like search, but only
m.group(i=0)
unused* in m)
returns the number of
r.exec(s)
finds matches starting at
th
substring matched by the i
m.captures
group list
matches, and stores the
position i
result for r’s first match in
group (null if that group is
matches in m structured
m.begin(i)
s, if r is local, or its next
m.group(i=0)
unused* in m)
according to the provided flag
m.end(i)
match in s, if r is global;
substring matched by
m.start(i=0)
f, which is one of:
null if no (more) matches
th
start and end offsets of the
the i
group (None if that
PREG_PATTERN_ORDER
m.end(i=0)
th
substring matched by the i
r.exec(s)[i]
group is unused* in m)
indexed as m[i][j], where i is
start and end offsets of the
group (nil if group unused* in
th
the i
matched group in
m.groups()
group list
the group number and j is the
th
substring matched by the i
the result
m)
match number
m.start(i=0)
group (-1 if group unused* in m)
$~
r.exec(s).index
PREG_SET_ORDER
m.end(i=0)
indexed as m[j][i], where i is
the MatchData object from the
offset of the match
start and end offsets of
the group number and j is the
most recent match
RegExp.$&
the substring matched
match number
$&
the entire text of the most
th
by the i
group (-1 if
the entire text of the most
recent match
group unused* in m)
recent match
RegExp.$1,
re.findall(q,s);
$1, $2 …
RegExp.$2 …
r.findall(s)
text matched by the 1
st
, 2
nd
, …
st
*Regular expressions note:
text matched by the 1
,
list of matched groups
groups in the most recent
nd
2
, … groups in the most
An expression or group that
from all matches in s,
match
recent match
matches an empty string
with '' for groups
nevertheless qualifies as used.
unused in a particular
A group may be unused in a
match. Entries are g-
match if it is part of a
tuples if the pattern
disjunction, for example.
contains g>1 groups, or
entire matches if g=0.
replace
str_replace(q,t,s)
s.gsub
(q,t)
s.replace(q,t)
s.replaceAll(q,t)
!
preg_replace(r,t,s)
s.gsub
(r,t)
re.sub(q,t,s)
m.replaceAll(t)
!
s.replace(r,q)
str_replace(q,t,s,1)
s.sub
(q,t)
s.replace(q,t,1)
s.replaceFirst(r,q)
!
preg_replace(r,t,s,1)
s.sub
(r,t)
re.sub(q,t,s,1)
m.replaceFirst(t)
!
format
sprintf(s,…)
s % […]
s % (…)
String.format(s, …)
s.format(…)

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 3