How can I remove something from the middle of a string with regex?

gython

I have strings which look like this:

/xxxxx/xxxxx-xxxx-xxxx-338200.html

With my regex:

(?<=-)(\d+)(?=\.html)

It matches just the numbers before .html.

Is it possible to write a regex that matches everything that surrounds the numbers (matches the .html part and the part before the numbers)?

The fourth bird

In your current pattern you already use a capturing group. In that case you might also match what comes before and after instead of using the lookarounds

-(\d+)\.html

To get what comes before and after the digits, you could use 2 capturing groups:

^(.*-)\d+(\.html)$

Regex demo

In the replacement use the 2 groups.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I remove arabic words from turkish string with regex?

How can I remove a specific format from string with RegEx?

How can I use a regex to remove HTML tags from a String?

How I can use regex to remove repeated characters from string

Regex to remove "-" from the middle of a timestamp string in postgresql

How can I extract text from the middle of a string with Javascript?

how can i select a specific string in RegExp From the middle

How can I get 2 characters from the middle of a string?

How can I remove leading zeros for two digits number (01, 02, etc.) from the middle of character string using R?

How remove a character from the middle of a string in excel

Using Perl with Regex, how can I remove a string within a string?

How can I remove a word from a string?

How can I use awk to insert something in the middle of the word?

How can I define a Regex to remove [xx]xxxxx[arch] xxx from a string?

How can I remove all non-alphanumeric characters from a string, except for '#', with regex?

How can I remove a specific character from multi line string using regex in python

How do I remove characters from the beginning and end of a string, but not from the middle?

How can I use regex to remove a very specific portion of a string:

How can I increase a number in the middle of a string?

How to remove new lines in a middle of a string using regex

How can I use regex to remove scripts from html tag

How can I remove the parenthesis from a regex result in swift 5?

Can I print something in the middle of a function?

Remove zeros from middle of string

Remove character from the middle of a string

How to use regex in Java to remove something from the name?

How can I select something from a listbox

How can I write a simple regex to match an optional middle group?

Remove leading zeros in middle of string with regex