Newest regex Questions

Q&A for professional and enthusiast programmers

Extract string if found using regex

Given myStr: "The pressure is" or "The number could be 4.4psi" And the desired results: "The pressure is" or "The number could be" result = /(.*?)\d+\..*/g.exec(myStr)[1].trim(); which will work ...

How do I use Regexp.union within another regular expression?

Using Ruby 2.4. I want to create a regular expression by saying match an arbitrary number of spaces followed by a letter that occurs in my array. So I tried this LETTERS = ["a", "b"] # => ["a", "...

Applying more than one attribute using regex in a switch statement

I would appreciate a set of fresh eyes on this. In sum, the function below tests a number of regex patterns against a string and sets attributes. The last pattern to be tested in the switch ...

How to replace a pattern using regex in python?

I have a dataset that looks like this: Male Name=Tony; Female Name=Alice.1; Female Name=Alice.2; Male Name=Ben; Male Name=Shankar; Male Name=Bala; Female Name=Nina; ### Female ...

Extract Digits From Matlab String

In Matlab, let's say that I have the following string: mystring = 'sdfkdsgoeskjgk elkr jtk34s ;3k54352642 643l j3kf p35j535'; And I want to extract all the digits in it to a vector such that each ...

username rewriting taking last /

What I've been trying to do is to rewrite url from domain.com?profile.php?id=foo to domain.com/foo and this condition works, and in the php to get the username i use $_GET['id'] And it works untill ...

regex - The program has unexpectedly finished [duplicate]

I tried to wrote regular expression to parse page source. If i use this: std::regex pattern("count\">\n\\((\\d*)\\)(.|\\s){3}small"); Program work correctly, but if i use this: std::regex ...

Ignore <input> tags with HTTP/S when removing protocols

I run a PHP script in WordPress that removes the http: and https: protocols from all the links, this is the full code, but here's the section that strips the protocols: # If 'Relative' option is ...

Subset dataframe if a $ symbol exists in a string column

I have a dataframe with a time column and a string column. I want to subset this dataframe - where I only keep the rows in which the string column contains a $ symbol somewhere in it. After ...

Find specific directory and change file name in the directory

I wrote down this code to find specific directory. read dir find -type d | grep $dir and I'd like to check whether $dir exists or not in the folder. How can i check the existence of the specific ...

Extract strings from pattern string1.string2'string3 where string1 can contain a '.' character

I need a regex to extract string1, string2, and string3 from a string of the form: string1.string2'string3. The separators '.' and ''' may not be present in the input. The problem is that string1 may ...

Regex search in page http and https [duplicate]

I have this php code: $cinemagiaprepare=file_get_contents("http://www.bing.com/search?q=$numele+$anul+site:https://www.cinemagia.ro/filme/&format=rss&count=1"); $cinepatern='#<\/title>...

Search for every line containing 'X' then replace the fourth element Regex

I have several tables that I'm trying to update. I need to update the fourth element of each table, when the first element matches a certain string. Example table (in Lua): TABLE = { {TEXT1,0,4,0,...

Java - how to print inside ANY HTML tag using regex matcher and pattern

I am writing a console command to print what is inside ANY HTML tag that the user desires. The command goes like this: ALL <tag> Where <tag> is for example <b> and the programs job ...

how to remove part of matched string in javascript

I would like to delete part of the string that is matched with a regular expression. My approach is to find a match, then str.replace() it with a blank ''. However, for the following text, I am having ...

Why is my string matching something in an array when that string doesn't contain any of those characters?

Using Rails 5 and Ruby 2.4. I can't understand why the below is matching . I have an array of strings and I want to see if my string matches any of those in the array, so I tried this 2.4.0 :021 >...

Regex ninjas - Why this different behaviour?

Working with this regex private static Pattern lf = Pattern.compile("(\\[(\\d+):(\\d+).(\\d+)\\])(.*)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); private void decode() { Matcher m = lf....

Regular expression - replace multiple html tags with one

is there a regular expression or any way to replace the following: some content...<span style='color:red'>t</span><span style='color:red'>e</span><span style='color:red'&...

Python regex error: bad character in group name

Can someone tell me why this regex works fine on oneline regex websites but not while using re.compile() in python. I have used this website: https://regex101.com/ and tested string is: "test": "...

Regex match prefix to suffix without either inbetween

If my prefix is < and my suffix is >, then I would want to match only the bolded parts of this string: .<.<.>.>.<.<.>.>. Since the affixes are single characters, this regular ...

Check if a String does not only contain integers

I am trying to execute a block of code on a String if it does not contain only integers. For example, if input is 2017, nothing will happen; else if it's 2017abc, the block of code will be executed. ...

Regex. Get the first space instead of second

I have this text 'Amber Costa Rica' and I want to separate it in 'Amber' and 'Costa Rica' I'm using with php preg_match('/(.*) (.*)/', $details_as_text, $matches); but it gives me array (size=3) ...

Regular expression, not outputting values correctly

num = re.findall (r'[-+]?\d*\.*\d+' , str (table)) Hi all I have this regular expression and it is printing the values i want. However, they are separated. For example: ['7', '336.82', '-3.89', '-...

What is the regular expression for word boundaries?

Some background, I found almost what I am looking for in: Regular expression Anchors examples Match beginning of line $ grep '^L' file **L**ine one Match end of the line $ grep 'e$' ...

Regular expression: re.findall() for set of all alphabetic words

I'm trying to using re.findall() function to test on a sentence that has a set of all alphabetic words. Here's my code: import re s = 'Hello from the other side' lst = re.findall('[:alpha:]', s) ...

Regex do not contain repeated substring

I came across regex that do not contain substring 110 and 110110: Regex 110: 0*(1|000*)0 However when it comes to regex 110110 I couldn't figure out the logic behind.

Remove unwanted characters from string with regex

This Meteor server code using cheerio to extract text from html: ` const myLines = ResObj.$('.panel-body').text(); Which console.log the following: Using regex, how can I get only non-empty lines, ...

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

I was wondering how I can use regex to remove a specific portion of a string. For example, I have a list that looks like this: name=derek; name=derek.1; name=derek.2; name=derek.3; name=ophelia; ...

How to code this identity in regex?

This is out of curiosity as I am getting my head around the confusing world of regex. I have a list like this: ID=maker.abc_g1_1G252; ID=maker.abc_g1_1G252.1; ID=maker.abc_g1_1G252.1.exon1; ID=...

How to get an e-mail address from a webpage using user input and a regex expression

I need help getting an e-mail address from a webpage using a REGEX expression in Android Studio. The user will input a name, and the e-mail address will contain this name as a substring, somewhere in ...

I want to use AND grep operation, but i don't know how

There are one program named pro1 and one data file named file1 in the folder. In data file, Alex|New york karlos|011-1234-5678 Karl|Chicago koroq|012-3456-7890 Richard|New york ntown|023-4567-8990 ...

PHP - Remove query string from font URLs

I have this string (sample) in a PHP variable: @font-face { src: url('../some-font.eot?v=4.6.3'); } I need to search by .eot? on every line. If found, do a replace that results in: @font-face ...

rails: validates_format_of use regex to limit line of numbers

I'm try to use regex to limit line of numbers, I have tried this, does not work like what I thought. I have a Product model has only info attribute, and it has one validation validates_format_of :...

JS regex to match a username with specific special characters and no consecutive spaces

I am pretty new to this reg ex world. Struck up with small task regarding Regex. Before posting new question I have gone thru some answers which am able to understand but couldnt crack the solution ...

How to create regex pattern for arbitrary range of surrogate pairs

In "narrow" Python builds we should use special regex pattern to match range of surrogate pairs. This pattern can be rather complex: # Pattern we want: pattern = '[\U000105c0-\U0001cb40]' # Pattern ...

Matching against a specific URL in Javascript with Regex

I'd like to invoke some Javascript only if I'm on a specific URL with a random subdomain: https://*.testsite123.io/testsite123/portal/#/login. So far I came up with function escapeRegExp(str) { var ...

Im using nginx to proxy requests to my backend application server. I want to strip a particular query string from requests that are coming through

Im using nginx to proxy requests to my backend application server. I want to strip a particular query string from requests that are coming through. My location block looks like this but its not ...

How to modify the format of all the values in particular column in Perl array?

I was reading each row from a result set (multi-dimensional array, as rows and columns are dynamic) and modifying the format for all date fields at specific positions in the array. But this is taking ...

John's Statement: Hello, How are you? - Split

I am currently using VB.net and in one of my task I need to compress a file , but I need it to do the following: For example: John's Statement: Hello, How are you? This need to split into: 1.John ...

.gitignore - ignore file starting with ~

To ignore any file starting with ~(tilde), I put following in gitignore file ^~.* But, it is not working for the file name starting with ~(eg. ~$ofession email.docx). There is no issue with ...

RegExp() generate wrong pattern for MongoDB $regex [duplicate]

I want to search the below regex pattern using $regex in MongoDB '/suggestions.php?q=12345' I tried the below code console.log(new RegExp('/suggestions.php?q=12345', 'i')) result is //...

python regex to group numbers

im trying to caputre numbers from that kind of a string: "30098.904999 5 ABC Da d 8 06 01 20 00 80 11 C0 04" first i remove all whitespaces: test = ' '.join(test.split()) ...

Converting from sub_match<const char *>' to 'const char *const &'

I am trying to map std::match_results data to my std::multimap variable. Here's the code: #include "Precompiled.h" using namespace std; using namespace tdd; auto main() -> int { auto ...

How to modify this code to include date in a new column?

I have unstructured text file that I need to extract some data from and put in structured format. The data look as below (each record expands on more than one row: 21 March 2017 23:10:45 text 21 ...

Django istartswith to match separate words within phrase

This post is exactly what I am looking for. But I wasn't able to achieve the goal using the info provided in the answer. I'll illustrate my goal by an example. For example, I have three strings: ...

Converting string into tokens

I am trying to split a string into tokens based on regex. However the split() gives error saying Illegal Escape Sequencce. I'm trying to split the following string into tokens. For example the ...

How to apply Formated mask to a textbox

I want to apply soles (S/.) symbol before my Values in textbox. For that there is alredy a question related to that link. In that answer there is some issue present for the first time there will no ...

Python re.findall without lookarounds and not multiline mode to capture everything besides specified string

Key to this problem is making sure to use re.findall NOT using lookarounds and not in multiline mode. This is partially because I also want to port it to use with regex libraries that don't support ...

Reges to catch different types of url having parameters

I have a regex that i need to be able to catch all full url that are found in a string. The url may have parameters and it still need to catch it. I have worked on it here: https://regex101.com/r/...

remove unwanted groups of characters from string using regex

Given: 1999 some text here 1.3i [more] Needed: some text here The following regex - replace(/[\d{4} |\d\.*$]/,'') - failed, it just removed the first digit. Any idea why and how to fix it? var s ...
Translating... 0%