Quantcast
Channel: Active questions tagged regex - Stack Overflow

A regular expression to match C-style string literals

I want to match all C-style string literals in a file:foo("Something went wrong", "another one")bar("This has an escaped \\ \"")baz("Let's go mad: \\ \" \\\\\\\\\"")Must match 4 times giving all those...

View Article


"length($d) == $s && $d =~ /^.{$s}$/" fails

Reading from shared memory, Perl treats the data as tainted, so I wrote a function that will untaint the data unconditionally (as I control the data being written to).As it failed sometimes, I also...

View Article


Get spaces count between nearest non-space character and given index

I have a string: ONT ONT ONT Auto-neg Speed Duplex Port Flow Native PriorityAnd i need to get Auto-neg from it (for example).I have start index of this word, for example 24.I need to get space count...

View Article

Is /[\s\S]/ the same as saying /.|\n/ in regex

I assumed in regex that saying:/[\s\S]/means the same as saying:/.|\n/But then I discovered that in JavaScript the line separator <0x2028> and the paragraph separator <0x2029> do not match...

View Article

How many backslashes are needed to escape characters in grep?

I'm a little confused about how many backslashes are needed to escape the alternation operator | in regular expressions for grep. Thisecho abcdef | grep -e"def|zzz"outputs nothing, because grep is not...

View Article


Remove characters from beginning and end or only end of line

I want to remove some symbols from a string using a regular expression, for example:== (that occur both at the beginning and at the end of a line),* (at the beginning of a line ONLY).def some_func():...

View Article

Ruby Email validation with regex

I have a large list of emails I am running through. A lot of the emails have typos. I am trying to build a string that will check valid emails. this is what I have for regex.def...

View Article

Using a regex as a template with Python

I have the idea to use a regex pattern as a template and wonder if there is a convenient way to do so in Python (3 or newer).import repattern =...

View Article


Searching for multiple matches on one line using Grep and Regex

I'm trying to use Grep with wc -l to print out the number of words in a text file that have 3 or more vowels in a row.Right now, I'm inputting:grep -i -E '<\.*[aeiou]{3}.*\>' file.txt | wc -lbut...

View Article


What regular expression captures most homophones related to the English words...

These strings of text are associated with the same sounds when spoken aloud:twotootoThe following is a valid regular expression.However, the following us not a very good solution, because only four...

View Article

What is a popular language used to generate regular expressions? [closed]

The syntax for regular expressions is very challenging for me to read, write, and understand.For example, it is very difficult for me to remember that an asterisk * has the same meaning as "zero or...

View Article

What is the optimized regex to match the email pattern in java

I am using the below regex in my program for matching the email pattern which is working fine.Pattern :...

View Article

How do I match any character across multiple lines in a regular expression?

For example, this regex(.*)<FooBar>will match:abcde<FooBar>But how do I get it to match across multiple lines?abcdefghij<FooBar>

View Article


Getting Initials from a name in R

I'm sure there's a more eloquent way:NAMES <- data.frame(ID = "George Washington")NAMES$ID <- as.character(NAMES$ID)gsub("", "", paste(substr(data.frame(strsplit(NAMES$ID, ""))[[1]], 1, 1),...

View Article

What is the \& pattern in Vim's Regex

I recently came across the branch specifier in Vim regex builtins. Vim's help section on \& contains this:A branch is one or more concats, separated by "\&". It matches the lastconcat, but only...

View Article


Extra non-character or empty character or absence is getting printed at the...

Consider the following codeString regex = "((\\d\\d\\d\\d)(\\w\\w\\w)(\\W\\W))*";String targetString = "$()1287jga$%dp5000tag%!5000tag%!5000tag%!q1";Pattern pattern = Pattern.compile(regex);Matcher...

View Article

Where can I find unit tests for regular expressions in multiple languages?

I'm building a regex helper at http://www.debuggex.com. The amount of detail I want to show requires me to write my own parser and matcher.To make sure my parser and matcher work correctly, I've...

View Article


replaceAll error [duplicate]

This is my regex. I want to find the opening and closing parentheses and replace them with "\(" and "\)".word = word.replaceAll(Pattern.quote("("), "\\"+"(").replaceAll(Pattern.quote(")"),...

View Article

Regex str_replace

Would it be possible to incorporate a str_replace method with a regular expression, designed to catch url strings in a simple html < textfield > input type?I'm considering something simple like a...

View Article

Line's number using regex in Notepad++?

Is it possible to get the line's number using regex in Notepad++; what I want to do, is replacing:line1line2line3etc..with1-line12-line23-line3etc..

View Article

Php regexp get the strings from array print_r like string

I'm trying to list out here how to match strings that looks like array printr.variable_data[0][var_name]I would like to get from above example 3 strings, variable_data, 0 and var_name.That above...

View Article


preg_match not capturing obvious match [closed]

I'm at an utter bottleneck because of this issue. I'm sure I'm probably making some extremely simple mistake, but I have no idea what it could be.I have a variable $html, which contains a string of...

View Article


RegEx to extract a name after a string is found in a string

I am trying to check if a string is in a string using RegEx in a AutoHotKey script.If my string is a file path like this:G:\htdocs\projects\webdevapp\app\folder\file.phpThen I need to extract the...

View Article

How to exclude images from regex email extraction

I am using some email extractor software to (surprise surprise) extract emails from websites. It uses the regex: [A-Z0-9._%+-]+@[A-Z0-9.-]{3,65}\.[A-Z]{2,4}But this churns out images as well as emails...

View Article

Why telegram emoji numbers are not deleted when removing special characters

I have a telegram bot and I want to remove all special characters and just returns numbers and A-Z,but the problem is that my regex pattern can remove any emojies except numbers like this...

View Article


Regex to remove ANSI escape sequences from script output

I'm trying to write a regex to remove all that starts with '[' and ends with 'm' or ';' so that the following script will be purged of all its special chars:Script started on 2023-09-16 10:06:45-04:00...

View Article

Use a regex to get text from html source code

I have got a php code that stores html source code of a site in a variable and I want to get two links from that source code only.First link is in meta tag key content:<meta property="og:image"...

View Article

How do I combine 2 instances of java.util.regex.Pattern? [closed]

I have 2 different instances of java.util.regex.Pattern. How do I combine them so that both apply?My use-case is that I am building a search tool, and I am giving users the ability to add all sorts of...

View Article

Some capture groups seem lost when matching group repeatedly

Trying to parse the output of monitoring plugins I ran into a problem where the match result was unexpected by me:First consider this debugger session with Perl 5.18.2: DB<6> x $_0...

View Article



Regex character repeats n or more times in line with grep

I need to find the regex expression to find a character that repeats 4 or more times with grep.I know that the expression is {n,}, so if I need to find lines, for example, when the character "g"...

View Article


Latest Images