Re: Regular expression validation
Knute Johnson <[email protected]> Mon, 10 Nov 2025 15:59:36 -0600
| Newsgroups | gmane.comp.apache.user |
|---|---|
| Message-ID | <[email protected]> |
I wrote a short perl script for you:
#!/usr/bin/perl
my $string1 = "now is the time for all good"; # ends with good
my $string2 = "now is the time for all good/"; # ends with good/
my $string3 = "now is the time for all good/men to come"; # ends with
good/something
my $regex = "^(.*good)?(/)?(.*)\$";
if ($string1 =~ m/$regex/) {
printf "string1 \$1=$1 \$2=$2 \$3=$3\n";
}
if ($string2 =~ m/$regex/) {
printf "string2 \$1=$1 \$2=$2 \$3=$3\n";
}
if ($string3 =~ m/$regex/) {
printf "string3 \$1=$1 \$2=$2 \$3=$3\n";
}
knute@knute-XPS-8700:~$ ./match.pl
string1 $1=now is the time for all good $2= $3=
string2 $1=now is the time for all good $2=/ $3=
string3 $1=now is the time for all good $2=/ $3=men to come
It might be simpler to capture the whole string and remove the /? Some
actual data to see what you are trying to do would be helpful.
^ - start
(.*good) - capture anything including the word good
?(/) - capture a / if there is one
?(.*)\$ - capture the remainder of the string if there is any
There may very well be differences between perl's regex and apache's.
knute...
On 11/10/25 14:36, Darryl Baker wrote:
> Is there a mailing list where I can ask regular expression help?
>
> I want to match line that end with a word or the word and a slash or the
> word slash anything ‘/(.*)$’
>
> I know the last case but making sure the regex covers the first two
> cases is what I am unsure about.
>
> Examples:
>
> https://www.example.com/foobar
>
> https://www.example.con/foobar/
>
> https://www.example.com/foobar/anything
>
> *Darryl Baker, *GSEC, GCLD** (he/him/his)
>
> Sr. System Administrator
>
> Distributed Application Platform Services
>
> *Northwestern University*
>
> 4^th Floor
>
> 2020 Ridge Avenue
>
> Evanston, IL 60208-0801
>
> [email protected] <mailto:[email protected]>_
>
> (847) 467-6674 <tel:+18474676674>
>
--
Knute Johnson
[email protected]