Questions tagged [regex]

Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Specify the language (PHP, Python, etc) or tool (grep, VS Code, Google Analytics, etc) that you are using. Do not post questions asking for an explanation of what a symbol means or what a particular regular expression will match.

regex
Filter by
Sorted by
Tagged with
1 vote
3 answers
452 views

Regular expression match multiple substring

I have written a regular expression to test how a string is a logical expression or not. Here is the regular expression: /(.*)(<|>|<=|>=|=|!=)(.*)/ And here is the subject which I tested ...
kukko's user avatar
  • 653
0 votes
1 answer
265 views

T9 Algorithm too slow

I am trying to implement T9 to my android dialer. But it lags. I checked and generating the list of possible combinations is painless. But I am trying to match using a pattern and I generated the ...
Amanuel Nega's user avatar
  • 1,947
0 votes
1 answer
127 views

stringr:: functions drops or ignores locale

I am stuggeling with R and stringr. When performing str_trim, str_upper etc my danish characters are converted into unicode charaters: library(stringr) library(stringi) Clean_String <- function(...
henrikwh's user avatar
-4 votes
3 answers
61 views

How to Remove Specific Letters from each word in a String - PHP [closed]

Suppose I have this string: Hello World Hello My World I want to remove first 3 characters in the entire string (but only if the word starts with 'Hel'). Output should be: lo World lo My World ...
Chintan Jain's user avatar
-1 votes
5 answers
2k views

Replace leading zeros with spaces

I have a text file of multiple records. Each record has a field which has some number of leading zeros that I need to replace with that number of spaces. A record will look like this: A206 ...
NathanK's user avatar
  • 101
97 votes
6 answers
101k views

Replace newlines with literal \n

This stackoverflow question has an answer to replace newlines with sed, using the format sed ':a;N;$!ba;s/\n/ /g'. This works, but not for special characters like \r, \n, etc. What I'm trying to do ...
Parze's user avatar
  • 973
0 votes
1 answer
445 views

Scala: regex directly in pattern matching block

I have following regex with pattern matching: val url = "/en/about" val langRegex = "/(.{2}).*".r val lang = url match { case langRegex(lang) => lang case _ => "en" } But I want to ...
Teimuraz's user avatar
  • 9,115
0 votes
1 answer
2k views

Regex Match string if it exists

Example 1: THE COMPANIES ACT (Cap 486) IT IS notified Example 2: THE COMPANIES ACT (Cap. 486) Incorporations IT IS notified My current regex: THE COMPANIES ACT\n\(((?:Cap.|Cap) .*?)\)(?:\...
Zacharia Mwangi's user avatar
0 votes
1 answer
771 views

Scala parse currency amount and remove the currency sign

I have currency string that i want to convert into Double value: val num = "181.13 kr" val parsed = num.replaceAll("\\p{Sc}|,", "") parsed = 181.13 kr This example not working but in this case this ...
david hol's user avatar
  • 1,272
0 votes
1 answer
66 views

How to get an array of matches and misses using regex in Javascript?

I want to extract anything between two square brackets, whilst keeping non-matched strings, up to the point of the next match, in an array. For example: var string = "Keep [[this]] and [[this too]]";...
Omair Vaiyani's user avatar
-1 votes
2 answers
154 views

How to split a statement based on dots ('.'), while excluding dots inside angular brackets(< . >) using regular expressions in python?

I want to split statements by dots using regex in python, while excluding certain dots inside the angular brackets. eg: Original Statement : 'my name 54. is <not23.> worth mentioning. ok?' I ...
Aditya Kuls's user avatar
1 vote
3 answers
2k views

Find arabic words using regex

I using this pattern to find any word in the string: \b(\w{1,}) but this can't find arabic words. How can I change this pattern to find both english and arabic words? Thanks
P.Karimyan's user avatar
1 vote
2 answers
3k views

PHP Regex to find a substring from a big string - Matching start and end

I want to find title of pages from a huge haystack but that do not have any class or unique id, so i can't use DOM parser here, i am aware i must use regular expressions. Here is example of what i am ...
Noman Ali's user avatar
  • 3,310
1 vote
3 answers
56 views

selecting N particular tables from MySQL

I have a mysql db and have 100 tables in it named, table_1, table_2, table_3 etc... In my bash script I only want to select 10 tables at a time say from table_20 to table_29. I tried the following ...
pku's user avatar
  • 79
-2 votes
1 answer
64 views

Regex uppercase certain letters

I would like to use regex to uppercase the letter c in certain circumstances (e.g.) if the C is for Celsius. My regex so far: ((?!\s)[c](?=\s)|(?!\d)[c](?=\d)|[c](?=-)) Example text: Some plastic ...
MoreScratch's user avatar
  • 3,023
1 vote
1 answer
35 views

How to remove pattern stuffs from preg_replace results?

I have this code : $text='This [word] should be a link'; echo preg_replace('/\[\w+\]/', "<a href='#'>$0</a>", $text); Output : This <a href='#'>[word]</a> should be a link ...
Amin Gholibeigian's user avatar
-1 votes
1 answer
32 views

Regex String Replacement and Split using PHP

I have a sample string in PHP: $var = 'lurm limsrh domw en wonf src="@storage//user1/path/file.txt" and any lorm lipsm tjp quor it src="@storage//user2/path/file.txt" utt fine @storage// no chnge'; ...
Prashant's user avatar
  • 393
-2 votes
1 answer
61 views

Regex to detect text symbols in single quotes

Please, I need you to help me with the next assignment. I need to create a regular expression that allows me to get all text in single quotes that have symbols. I am using the following expression: [...
apetitflores's user avatar
0 votes
1 answer
739 views

Remove a character from the middle of a string with regex

I have no programing experience and thought this would be simple, but I have searched for days without luck. I am using a program to strip content from a web page. The program uses regex filters to ...
SkipperC's user avatar
18 votes
1 answer
21k views

How do I remove newline from Java stacktraces in logback?

I'm trying to remove newline from Java stacktraces. I've following logback pattern - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %replace(%msg){'\n', ''}%n</pattern> I ...
user375868's user avatar
  • 1,338
1 vote
1 answer
369 views

multiline textbox validation ms access

Hi I am pretty new to Ms Access and I could use some of your expertise to advise: I would like to validate the text of a multiline textbox, so that the user can only enter 2 capital letters - 7 ...
Julie Morabito's user avatar
-1 votes
1 answer
53 views

JavaScript regex field value

Hi I'm trying to see if a value does not equal something with this code if !(regx.test(field.value)) I know that if (regx.test(field.value)) this works fine, I would just like it to do ...
Michael's user avatar
  • 51
1 vote
2 answers
94 views

Babeljs produces unexpected error for regex {m,n} quantifier

I have the following: const checkCode = code => { if( /^\+[0-9]{3}/[0-9]{3}[A-Z]+[0-9]{3}$/.test( code ))){ return true; } //run more code... } Babel transpiler produces an ...
Stephen Isienyi's user avatar
0 votes
2 answers
29 views

Find multiple quoted strings

Given this: var str = "this.get('contact.firstname') + ' ' + this.get('contact.lastname')"; How do I get ['contact.firstname', 'contact.lastname']; I've been trying a while and the latest ...
GreginNS's user avatar
  • 161
0 votes
2 answers
44 views

RegEx: Removing select parts of a URL, except variables

Trying to remove parts of a URL via RegEx. I'm getting my content via an AJAX requst thus I cannot use $(location).attr('search').split("&")[2] My RegEx (Regex101) Any direct answer will be ...
user avatar
1 vote
2 answers
126 views

How to find if a string contains a word between two colons, then return that result including the colons

I'm writing a bot for Discord, and I want to be able to detect if a string contains a substring that is in the format :smilie:, for example "I am so excited for this video game! :getin:". Currently ...
Tadhg's user avatar
  • 476
-1 votes
3 answers
46 views

I need a regex expression to separate each word and <br>

What I need is super straight forward however I simply cannot figure it out. I am using regex101.com to try and nail down the correct regex but nothing seems to work. Basically what I need is to ...
Chris James Champeau's user avatar
5 votes
4 answers
7k views

Postgres invalid regular expression: invalid character range

I'm using the following line in a postgres function: regexp_replace(input, '[^a-z0-9\-_]+', sep, 'gi'); But I'm getting ERROR: invalid regular expression: invalid character range when I try to use ...
Asherlc's user avatar
  • 1,151
3 votes
2 answers
3k views

How to match a backspace character in a regular expression in Vim ex command?

Do I use a unicode character substitution? I've seen posts saying use "\b" but that's a word boundary as far as I know. I'm asking because I saw it in a Vimgolf problem: Vjd:%s/.<BS>,/\r/g<...
Nona's user avatar
  • 5,392
1 vote
1 answer
3k views

Regex LookAhead limit to one (or first match)

I'm trying to match the string (the answer) between numerous pre-set questions. The questions are jumbled, but they do start with "Question:" in front of each question. Followed in new line by "Answer"...
Unu's user avatar
  • 711
0 votes
1 answer
689 views

Replace lines in text file inside tar file with sed and regular expressions

File b.txt in a tar file b.tar contains lines such as these: dir1 => /dir1A dir2 => /dir2A I would like a concise expression for replacing it inside the tar file with a version with these ...
Drux's user avatar
  • 12.3k
0 votes
1 answer
18 views

Express route parsing hit routes it should not

I have the following two route: router.get('/:postId([0-9]*)', handler) router.get('/:postId([0-9]*)/like', handler) The first route should capture only urls like /posts/4352/, but not /posts/3422/...
NoNameProvided's user avatar
-2 votes
2 answers
1k views

Python use regex to match characters for number, letter, space and brackets

I know that to match only numbers letters and space, I can use: re.match(r'[A-Za-z0-9 ]+$', word) but I would like to also match brackets such as (), {}, []. I extended the above regex to : re....
J Pang's user avatar
  • 9
1 vote
2 answers
189 views

The most regex-y way to understand commutative operations?

I want to parse both 1.05*f and f*1.05 to be equivalent things where f is a fixed letter, the number is any positive float and the * is always between the 'f' and the float (i.e. multiplication). If ...
FinanceGuyThatCantCode's user avatar
-2 votes
1 answer
84 views

Hit different regex pattern and then give different weight in C#

I have regex patterns (about 100 or so) which are implemented using Regex class in C#. Now I want to give different weights when my input strings hit different patterns, for instances: input_string ...
Mrk421's user avatar
  • 5
0 votes
0 answers
55 views

creating list with multiple regex

I have a information in the format - AAMOD, Robert Kevin; Salt Lake, '91; Sales Associate, Xyz, UT; r: 101 Williams Ave, Salt Lake City, UT 84105, cell: (xxx) xxx- xxxx, [email protected]. I am trying to ...
Paridhi Saxena's user avatar
0 votes
1 answer
406 views

Using python 2.7 - regex to find all CR character at end of lines

I have a folder with about 50,000 text files in it, and I need to see if any of them have lines that end in the CR character only (not CR/LF, or LF) - hex 0x0D. The following code doesn't return any ...
SO-Darkater's user avatar
2 votes
1 answer
165 views

Pandas: filtering rows from data based on multiple criteria using ~mask

I am trying to filter out rows from my data: cid date catcode amtsum 145403 N00000286 2009 F1100 0.500 199228 N00000286 2009 Z5100 4.000 485489 N00000286 2007 B4000 ...
Collective Action's user avatar
1 vote
2 answers
150 views

How can I parse MARC records with a Regular Expression?

I would like to parse a MARC record with a regular expression and return the field as the first captured group and the value as the second captured group. Here's what I've got thus far for the regex: ...
JakeParis's user avatar
  • 11.1k
0 votes
1 answer
75 views

Regex constraint in rails route

I have a route to which I am adding a constraint for an integer to be anywhere between 0-2 i.e. the integer can either be 0,1 or 2. I tried something, but that's not helping. Route: get 'books/:...
tech_human's user avatar
  • 6,792
1 vote
2 answers
100 views

How to capture "*" as argument to bash function and use in a comparison

I want to have bash run rm -i * if I type rm * but otherwise run regular rm. Importantly, I don't want to run rm -i every time I use a wildcard such as rm part*. Here is as far as I could come up with:...
abalter's user avatar
  • 10.1k
1 vote
1 answer
44 views

Not greedy regex does not work

My Regex: \@((TIME|NOW|TODAY)\(.*?\)\s+[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]) My String: @Time blah blah @TIME(1d) blah @NOW(12312) 12:32:25 blah @TODAY(12312) 12:32:25 What I expect to match: @NOW(...
DaBears's user avatar
  • 301
2 votes
1 answer
923 views

Grok debugging - Match first only regex not working as intended

So I have the following log message: [localhost-startStop-1] SystemPropertiesConfigurer$ExportingPropertyOverrideConfigurer loadProperties > Loading properties file from class path resource [...
A_Elric's user avatar
  • 3,548
0 votes
2 answers
419 views

Bash: regular expressions within backticks

I have a file called "align_summary.txt" which looks like this: Left reads: Input : 26410324 Mapped : 21366875 (80.9% of input) of these: 451504 ( 2.1%) have multiple alignments (...
D. Kazmin's user avatar
0 votes
1 answer
95 views

Split array by regular expression in Node.js

I'm using https://github.com/joyent/node-strsplit to split the text extracted from a file. I need to extract the data between double curly braces. Following will be some sample text in the file. I ...
Amila Iddamalgoda's user avatar
0 votes
1 answer
36 views

Rewriting RewriteRule to include back one particular php file in the path

I inherited a large WordPress site: I was looking at the Wordfence live logs when I found users not loading a particular PHP page. I investigated and through an FTP client I found the file was where ...
user avatar
1 vote
1 answer
1k views

Regex for optional end-part of substring

Consider the following (highly simplified) string: 'a b a b c a b c a b c' This is a repeating pattern of 'a b c' except at the beginning where the 'c' is missing. I seek a regular expression which ...
Ole Thomsen Buus's user avatar
3 votes
2 answers
249 views

Why isn't RegularExpressionValidator matching my regular expression?

I'm having a problem trying to validate a asp:TextBox control using a asp:RegularExpressionValidator. I've simplified the regular expression that I am using and have isolated that the ...
Ɖiamond ǤeezeƦ's user avatar
-1 votes
4 answers
74 views

Substring replacement in MySQL

I have fields like this table in mysql database, <table border=1 ><tr><td>No</td><td>Value</td></tr> <tr><td>1</td><td>System ...
Prabowo Ignatha's user avatar
0 votes
1 answer
121 views

Regex to find a word between any sequence of number and a word

I'am trying to find word <fruit> the word color and white in these phrases @EDIT Adding more examples orange: 2 2 7: color he won juice rice: 1022 2 22: white he won lunch apple: 1022 2 22:...
Davi Pereira's user avatar