<?php
$s_Test = <<< END_TEST
/
/?var1=1&var2=2
/page.asp
/page.asp?var1=1&var2=2
/folder1/page.asp
/folder1/page.asp?var1=1&var2=2
/fol.der.1/page.asp
/fol.der.1/page.asp?var1=1&var2=2
/folder
/folder1/folder2
/folder1/folder2?var1=1&var2=2
/fol.der.1/folder2
/fol.der.1/folder2?var1=1&var2=2
END_TEST;
foreach(explode(PHP_EOL, $s_Test) as $s_Line)
{
if (1 == preg_match('%^/(?:[^?]+/[^./]++|[^/?.]+)$%im', $s_Line, $a_Match))
{
echo $s_Line, PHP_EOL;
}
}
<?php
$s_Test = <<< END_TEST
/
/?var1=1&var2=2
/page.asp
/page.asp?var1=1&var2=2
/folder1/page.asp
/folder1/page.asp?var1=1&var2=2
/fol.der.1/page.asp
/fol.der.1/page.asp?var1=1&var2=2
/folder
/folder1/folder2
/folder1/folder2?var1=1&var2=2
/fol.der.1/folder2
/fol.der.1/folder2?var1=1&var2=2
END_TEST;
foreach(explode(PHP_EOL, $s_Test) as $s_Line)
{
if (1 == preg_match('%^/(?:[^?]+/[^./]++|[^/?.]+)$%im', $s_Line, $a_Match))
{
list($s_Path) = explode('?', $s_Line);
echo $s_Path, ' vs ', $s_Line, PHP_EOL;
}
}
<?php
$s_Test = <<< END_TEST
/
/?var1=1&var2=2
/page.asp
/page.asp?var1=1&var2=2
/folder1/page.asp
/folder1/page.asp?var1=1&var2=2
/fol.der.1/page.asp
/fol.der.1/page.asp?var1=1&var2=2
/folder
/folder1/folder2
/folder1/folder2?var1=1&var2=2
/fol.der.1/folder2
/fol.der.1/folder2?var1=1&var2=2
END_TEST;
foreach(explode(PHP_EOL, $s_Test) as $s_Line)
{
if (1 == preg_match('%(?=^/[^?]+/[^./]++$|^/[^/?.]+$)([^?]+)\??(.*)%im', $s_Line, $a_Match))
{
print_r($a_Match);
}
}
string resultString = null;
try {
Regex regexObj = new Regex(@"(?:(/[^?.]+)(?:\?(.*))?)$", RegexOptions.IgnoreCase | RegexOptions.Multiline);
resultString = regexObj.Match(subjectString).Groups[1].Value;
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
===========
var
RegexObj: Regex;
ResultString: string;
RegexObj := nil;
ResultString := '';
try
RegexObj := Regex.Create('(?:(/[^?.]+)(?:\?(.*))?)$', RegexOptions.IgnoreCase or RegexOptions.Multiline);
ResultString := RegexObj.Match(SubjectString).Groups[1].Value;
except
on E: ArgumentException do begin
// Syntax error in the regular expression
end;
end;
============
var
Regex: TPerlRegEx;
ResultString: string;
Regex := TPerlRegEx.Create(nil);
Regex.RegEx := '(?:(/[^?.]+)(?:\?(.*))?)$';
Regex.Options := [preCaseless, preMultiLine];
Regex.Subject := SubjectString;
if Regex.Match then begin
if Regex.SubExpressionCount >= 1 then begin
ResultString := Regex.SubExpressions[1];
end
else begin
ResultString := '';
end;
end
else begin
ResultString := '';
end;
=============
String ResultString = null;
try {
Pattern regex = Pattern.compile("(?:(/[^?.]+)(?:\\?(.*))?)$", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.MULTILINE);
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
ResultString = regexMatcher.group(1);
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
===========
var rx_Email = /(?:(\/[^?.]+)(?:\?(.*))?)$/im;
var match = rx_Email.exec(subject);
if (match != null) {
result = match[1];
} else {
result = "";
}
===========
if ($subject =~ m!(?:(/[^?.]+)(?:\?(.*))?)$!im) {
# Successful match
} else {
# Match attempt failed
}
===========
# Your regular expression could not be converted to the flavor required by this language:
# A POSIX Extended RE cannot match the start and the end of a line with ^ and $
# Because of this, the code snippet below will not work as you intended, if at all.
if (eregi('((/[^?.]+)(\?(.*))?)$', $subject)) {
# Successful match
} else {
# Match attempt failed
}
===========
$regex = [regex] '(?im)(?:(/[^?.]+)(?:\?(.*))?)$'
$result = $regex.Match($subject).Groups[1].Value;
===========
wxString resultString;
wxRegEx regexObj(_T("(?pw)(?:(/[^?.]+)(?:\\?(.*))?)$"), wxRE_ADVANCED + wxRE_ICASE);
if (regexObj.Matches(subjectString)) {
resultString = regexObj.GetMatch(subjectString, 1);
}
==========
Dim ResultString As String
Try
Dim RegexObj As New Regex("(?:(/[^?.]+)(?:\?(.*))?)$", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
ResultString = RegexObj.Match(SubjectString).Groups(1).Value
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try
===============
Dim ResultString As String
Dim myMatches As MatchCollection
Dim myMatch As Match
Dim myRegExp As RegExp
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.MultiLine = True
myRegExp.Pattern = "(?:(/[^?.]+)(?:\?(.*))?)$"
Set myMatches = myRegExp.Execute(SubjectString)
If myMatches.Count >= 1 Then
Set myMatch = myMatches(0)
If myMatch.SubMatches.Count >= 3 Then
ResultString = myMatch.SubMatches(3-1)
Else
ResultString = ""
End If
Else
ResultString = ""
End If
==================
Dim myRegExp, ResultString, myMatches, myMatch As Match
Dim myRegExp As RegExp
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.MultiLine = True
myRegExp.Pattern = "(?:(/[^?.]+)(?:\?(.*))?)$"
Set myMatches = myRegExp.Execute(SubjectString)
If myMatches.Count >= 1 Then
Set myMatch = myMatches(0)
If myMatch.SubMatches.Count >= 3 Then
ResultString = myMatch.SubMatches(3-1)
Else
ResultString = ""
End If
Else
ResultString = ""
End If
===============
regexp = /(?:(\/[^?.]+)(?:\?(.*))?)$/i
match = regexp.match(subject)
if match
match = match[1]
else
match = ""
end
============
Dim myRegEx As RegEx
Dim myMatch As RegExMatch
Dim ResultString As String
myRegEx = New RegEx
myRegEx.SearchPattern = "(?:(/[^?.]+)(?:\?(.*))?)$"
myMatch = myRegEx.Search(SubjectString)
If myMatch <> Nil Then
ResultString = myMatch.SubExpressionString(1)
Else
ResultString = ""
End If
===================
reobj = re.compile(r"(?:(/[^?.]+)(?:\?(.*))?)$", re.IGNORECASE | re.MULTILINE)
match = reobj.search(subject)
if match:
result = match.group(1)
else:
result = ""
======================
$regex = [regex] '(?im)(?:(/[^?.]+)(?:\?(.*))?)$'
$result = $regex.Match($subject).Groups[1].Value;
============
etc.
^/(?!.*\.)(?!\?).*$
Options: case insensitive; ^ and $ match at line breaks
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match the character / literally «/»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!.*\.)»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character . literally «\.»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!\?)»
Match the character ? literally «\?»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
Created with RegexBuddy