Slash in regular expression in Golang

Nguyễn Văn Thưởng :

I have two links:

1: /aaa/bbbb/ccccc.htm
2: /xxx/yyy.htm

What regex is able to match the second link?

I have tried:

^\/.*\/.*[^\/].* 

But, it match all of them.

Emma :

I'm guessing that we might want to pass both URLs, which in that case we would start with:

(\/[a-z]+)?(?:\.htm)?

We can then add more boundaries, if you wish.

RegEx

If this wasn't your desired expression, you can modify/change your expressions in regex101.com.

enter image description here

RegEx Circuit

jex.im visualizes regular expressions:

enter image description here

JavaScript Group Breakup

const regex = /((\/[a-z]+)?(?:\.htm)?)/gm;
const str = `/aaa/bbbb/ccccc.htm
/xxx/yyy.htm`;
const subst = `Group #1: $1\nGroup #2: $2\n`;

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log('Substitution result: ', result);


If you only wish to pass the second URL and fail the first one, you can simply add some boundaries to your expression, maybe something similar to this would work:

^\/[a-z]+\/[a-z]+.htm$

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java regular expression and "greedy" or early search for slash

Javascript regular expression: remove first and last slash

How to check for "/" slash in XML with Regular Expression

Regular Expression to also allow slash "/" with existing Regex

How to match a word based on slash in regular expression

two back slash in SQL procedure with Regular expression

Bash: String manipulation with sed and Regular expression is not working: replace a string by slash

Matching words with a forward-slash via Regular Expression

Regular Expression to find string starts with letter and ends with slash /

What does the forward slash mean within a JavaScript regular expression?

Regular expression to read only digits after last slash

Golang Regular expression always returns false?

golang regular expression to extract pairs of quantities and their units

Java regular expression value.split("\\."), "the back slash dot" divides by character?

How would I write a Regular Expression to capture the value between Last Slash and Query String?

How do I make this regular expression not match anything after forward slash /

skipping a forward slash in pig grunt shell to match a regular expression on every line

Regular expression to split a street address that may have optional numbers with slash or hyphen in between at the end

Why does this regular expression match group 2 in Golang and Python but not in JavaScript?

Regular Expression to mask any string matching 10 digits only in golang

The golang regular expression gets the SQL statement in the log file

Golang regular expression for parsing key value pair into a string map

golang how to split a string to a slice containing the delimeters using a regular expression

Can we use regular expression in Golang testable example Output comment?

Regular expression

"?!" in regular expression

Regular expression with an = and a ;

regular expression

AND in Regular expression