Questions tagged [regex]

Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Since regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool. NOTE: Asking for HTML, JSON, etc. regexes tends to be met with negative reactions. If there is a parser for it, use that instead.

0
votes
0answers
7 views

Better Time Complexity for a Sequential Necessary Regex Script?

Using regex to parse and identify different types of data Without including regex in my notation I have an informal O(n^3) time complexity and a formal notation of O(20.33n^3+84.22n^2+3n+14) Decimals ...
0
votes
0answers
7 views

Python RegExp re.findall() didn't act properly ? capture Integer in between certain pattern [duplicate]

I want to capture Integer in between certain string. My Regular Expression String is re_str ="HOWMUCH?*\s*_*\s*(\s*(\d+)\s*)_*\s*USD" target_text =" 1. HOWMUCH?__10_ USD 1. HOWMUCH?_20_USD 1. ...
0
votes
0answers
13 views

Google maps place id using selenium

from selenium import webdriver import re driver= webdriver.Chrome(executable_path=r"C:\Users\chromedriver") sentence ="chiropractor in maryland" url="https://google.com/search?hl=en&q={}".format(...
0
votes
2answers
35 views

Regex to get particular string from a response

I have a response like below <adm:TargetCode key="urn:comcast:altcon:activityState">INACTIVE</adm:TargetCode> <adm:TargetCode key="urn:comcast:altcon:activityState">ACTIVE</...
-1
votes
1answer
13 views

Why This error : sre_constants.error: nothing to repeat at position 2?

This is error happen when trying to match pattern pattern = re.compile(r'\b*\d{3} \d{3}-\d{4}\b*') def match_exactly(phone): phone = pattern.fullmatch(phone) if phone: return phone....
1
vote
1answer
35 views

How to replace multiple values in matching pattern from string

I want to search a pattern in a string and then again search some invalid character in matching pattern and then remove them or replace with some valid characters. I have some sample dictionaries eg. ...
-2
votes
2answers
29 views

How to include certain character in a regex pattern?

I need a little help. This is my first time using regex. So, I want to make sure that the user can only input a number and two other characters - period . and a comma ,. Whenever a user input a ...
0
votes
1answer
21 views

Ensure specific characters are in a string, regardless of position, using a regex in Golang

I am building a super simple function to ensure a password contains specific characters. Namely, the password should have the following: One lowercase letter One uppercase letter One digit One ...
1
vote
1answer
23 views

RegEx for matching a single-line standard USPS address

I am learning how to extract data from a string of data to define as variables and use as I'd like. The data source I am parsing is a standard email every time and the address is exactly the same ...
0
votes
1answer
19 views

Replace uppercase to lowercase within htaccess using regex

I have the following line in my htaccess file: RewriteRule ^images/9440/(([a-zA-Z0-9-]{2})[^/]*\.jpg)$ /images/9440/img-$2/$1 This an example of the URL that htaccess rule will apply to: /images/...
2
votes
2answers
21 views

Use regex_extract to retrieve the score number in a string text column

I need to extract the float number after score. {"reason_desc": { "score":"0.1", "numOfIndicatrix":"0", "indicatrix":[]}, "success":true, "id":"1555039965661065S427A2DCF5787920"...
0
votes
1answer
21 views

splitting a whitespace separated string, ignoring whitespace within single quotes

My Java input String str ="aa 2 xx 'b cc dd e' -o se '4-5'" I want to output the tokens delimited by white space, except for the white space within single quotes. So, the output should be: aa 2 xx '...
0
votes
1answer
21 views

Concatenate related fields and replace within data frame

I'm in the process of concatenating two related fields throughout a large dataset. I feel like I have most of what I need but can't concat the fields properly. dataframe: id| date1foo| time1bar| ...
0
votes
2answers
31 views

How to create a regex that will find a substring of a complex URL

Need some guidance on creating a regex that will identify part of the URL. URL1: test-project-233-TEST-ENDPOINT.test.as.ds.abcdefg.com URL2: test-project-124-ENDPOINT.test.dd.ad.gf.abcdefg.com The ...
1
vote
1answer
18 views

URL regex that skips ending periods

I'm trying to create a regex that matches url strings within normal text. I have this: http[s]?://[^\s]+ This seems to work well with the exception that if the url is at the end of a sentence it ...
0
votes
4answers
25 views

How to create proper regular expression to find last character which I want to?

I need to create regex to find last underscore in string like 012344_2.0224.71_3 or 012354_5.00123.AR_3.335_8 I have wanted find last part with expression [^.]+$ and then find underscore at found ...
2
votes
3answers
69 views

If-Then-Else regex statement

I am trying to form a regular expression that would capture <expression1> if it is in the string otherwise capture <expression2>. I tried something along the lines of: (IF)(?(1)THEN|ELSE),...
0
votes
1answer
17 views

Looping through tabs in Excel spreadsheet using regex for tab names

I am trying to loop through some Excel spreadsheets and pull information from certain tabs using regex. I have written the following code so far: import pandas as pd import os import re root = r"...
1
vote
0answers
21 views

How to return the smaller of an OR operator regex when both are present? [duplicate]

This regex: import re string ='I am a long string with many regexes matching' pattern ='.*(?:with|regexes)' print(re.findall(pattern, string)) returns ['I am a long string with ...
0
votes
0answers
14 views

How to solve regex exception for password in java [duplicate]

I am trying to implement a method that checks if a password respects a format using String.match. The problem is that I get this: Exception in thread "main" java.util.regex.PatternSyntaxException: ...
-1
votes
1answer
21 views

How to find the index for matched elements in a list in Python?

I have a list of names and I want to find the indices for names that partially match a pattern. For example, I want to search for "ohn" and find the indices of all names that have "ohn" in them> Here ...
0
votes
0answers
17 views

How to skip further processing after phrase is labeled in string?

I am searching through text and labeling expressions. The problem is I don't know how to stop the phrase search from finding smaller phrases inside the longer ones. For example, if my code finds What'...
0
votes
3answers
34 views

Regular Expression In Order To Identify Tor Domains

I am working on a scraper that goes through html code trying to scrape tor domains. However I am having trouble coming up with a piece of code to match tor domains. Tor domains are typically in the ...
0
votes
1answer
19 views

Convert text with tabs to a valide JSON with regex

I try to convert this plain txt exported from a audio sofware (audacity) 0.147652 0.983684 noing_grf 2.316547 3.609503 boing_4r4 To a valid json objet format like this { 'noing_grf':...
-3
votes
1answer
26 views

How to find formula pattern in a text document using regular expressions? [on hold]

I am doing an NLP task on user comments and I want to capture formula from a text and replace the whole with "FORMULA" tag for the purpose of cleaning. I am fairly new to regex and it is getting ...
1
vote
1answer
22 views

Catch word occurring multiple times within quotes

I need to catch all instances and variants of a class name using regex, but i can't figure out the correct pattern, currently it match the whole text inside quotes I intend to use the pattern with ...
0
votes
2answers
36 views

How can I fix this regex to match an object in Json and replace it as a list of Object

I have tried the following but i am failing to match the object in Json :\s*(\{[^\"]*\}) I want to know the way to replace the object type in Json as list of object. Here is the sample of Json: { ...
2
votes
2answers
49 views

How do I get the first and last initial/character from a name string

I am trying to extract the first character of both first and last name from a string but have had no luck so far.( tried searching multiple solutiosn online, no luck either) So for example, if this is ...
0
votes
0answers
17 views

Splunk regex line breaker, combining multiple ERROR [stderr] lines into one event

I am working on displaying logs from docker json-file in splunk. For the most part I have it working, except for when a stack trace is printed. I know e.printStackTrace() isn't best practice, but our ...
0
votes
1answer
15 views

Something in my regex is not recognizing images served from a location without an extension as valid urls

I have been working on a small script designed to pack an entire webpage into one single html file. I've been working on it all day, and so far, all images that have a proper extension are converted ...
0
votes
1answer
17 views

Insert Adjusted ASP Variable Cleaned with Regex into meta content=“” field

I have an asp variable [@@Price] that displays with extra content - $12.69/CS I'm having problems inserting the cleaned [@@Price] variable into meta field -specifically content="". I have the refex ...
-1
votes
0answers
31 views

How to exclude strings using Regex

I'm using Regex in Google Analytics to build a funnel for users moving through the website but am having trouble excluding pages/strings Here's the link to Regex in GA https://support.google.com/...
0
votes
1answer
25 views

RegEX for finding a random lowercase alphanumeric string bounded from right

I'm trying to create a simple application that will open and read a file, then will change the value of a property using dart. I've opened the file and then read, and I changed a value of a text and ...
1
vote
0answers
25 views

Strange behaviour with Boost regex and emojis

The emoji sequence "👩‍❤️‍💋‍👩" does not seem to be rendered as a sequence on notepad++ and regex101.com (It is rendered as 4-7 characters depending if you count the joiners) Anyways, I would expect ...
1
vote
1answer
20 views

Get numbers (including “-”) with non leading zero

I want to match numbers including "-" with non leading zeros and normal numbers without "-". Therefore I want to use a regular expression. The regex should match 0 1 2 3 123 2-3 22-33 and should ...
1
vote
1answer
22 views

Locate a sub-string with a general character '[a,z]-\n' and replace the non-general part of the sub-string '-\n'

I have text I am cleaning up in R. I want to use stringi, but am happy to use other packages. Some of the words are broken over two lines. So I get a sub-string "halfword-\nsecondhalfword". I also ...
0
votes
0answers
26 views

Use regular expression to determain whether user is trying to access phpmyadmin from a url [on hold]

I am trying to create an HTTP honeypot that logs all urls, and i want to implement a regular expression that will determine if a user is trying to access phpmyadmin or any other admin panel. how would ...
-1
votes
0answers
13 views

PHP preg_match and preg_match_all doesn't working properly [duplicate]

I'm trying to learn preg_match, preg_match_all and regex. I want to get lyrics from the site lyricstranslate.com I have these codes: preg_match('/'.preg_quote('<h2 class="title-h2 ">', '/').'(....
0
votes
2answers
27 views

Simplify Regex grouping

var pattern = (?:[P|p]rint\("")(.+)(?:""\);?) var input = Print("Hello World"); Results in two groups, the second one captures exactly what I want to capture and the first one is completely useless, ...
0
votes
1answer
25 views

JS Regex: Wrap content in multiple tags defined in appended lines?

I’m trying to replace content using JavaScript String replace as follows: From: line 1 line 2 ! foo ! bar ! baz To: <baz> <bar> <foo>line 1</foo> <foo>line 2</foo&...
0
votes
1answer
27 views

how can i extract a specific part of a string in c# with regex.match? [duplicate]

Though this is probably a duplicate, i haven't been able to make this work after reading similar questions. Looking for help please with this homework, i'm a newbie at programming. I'm working on a ...
2
votes
1answer
25 views

Regex solution for dataframe rownames

I have a dataframe returned from a function that looks like this: df <- data.frame(data = c(1,2,3,4,5,6,7,8)) rownames(df) <- c('firsta','firstb','firstc','firstd','seconda','secondb','secondc',...
0
votes
0answers
16 views

Redirect to page produces “too many redirects” but target page is excluded in RewriteRule

Trying to redirect users to expired page after a set time but the browser gets stuck in a "too many redirects" loop. The first line is the time condition and the second line excludes the redirect ...
2
votes
2answers
30 views

RegEx replacing numbers greater than variable in Javascript

I have the string: "selection1 selection2 selection3 selection4" I am looking to remove all words that end in a number greater than a variable. For instance: let str ="selection1 selection2 ...
0
votes
2answers
44 views

How to find name from string using Regex in NodeJs

Here is my code , i have written separate function for regex to extract name pattern, passing Regex Pattern with two strings to the function, function matches either one pattern from two input string ...
0
votes
2answers
25 views

Regex replace function not updating DOM in expected manner

I am trying to update my html using regex and javascript. I can capture the group I intend, however nothing on the dom is changing the way I would expect. I want to discover all currency mentions of ...
-2
votes
1answer
39 views

Need needed to get personal details of a person from string in java using regex for an android app [on hold]

I am new to regex so not familiar with the expressions. I am building a business card reader android app and for that i need to get details like name, phone, email address and address. My output ...
0
votes
1answer
21 views

Using Regex and Powershell to Return Multiple Lines of a File

I am using regex to return a portion of a file. This is what the bit of file looks like: L1*4***13258 S5*1*CL*9587*L*756*CA*1603*E G62*10*20190124*Y*1210*LT NTE*GEN*Pallets: FLOORLOADED N1*SF*FLOWERS ...
-2
votes
0answers
19 views

Python Regular Expression * +? [duplicate]

name1 ='sriiiraiim' mo1 = re.search('i+',name1) mo2 = re.search('i*',name1) mo3 = re.search('i?',name1) print(mo1.group()) print(mo2.group()) print(mo3.group()) ...
0
votes
3answers
33 views

Regex catch from the hash sign “#” to the next white space

I have a script line this : #type1 this is the text of the note I've tried this bu didn't workout for me : ^\#([^\s]+) I watch to catch type in other words I to get whats between the hash sign "#"...

http://mssss.yulina-kosm.ru