All Questions
5,392
questions
2
votes
2
answers
69
views
How can I get commands in Rails Migration file using regex?
I'm trying to get commands from a Rails migration file as an array based on a specific migration command, using regex. My code works well on most cases, but when there is a command with multiline code,...
5
votes
5
answers
135
views
Capturing all matches of a string value from an array of regex patterns, while prioritizing closest matches
Let's say I have an array of names, along with a regex union of them:
match_array = [/Dan/i, /Danny/i, /Daniel/i]
match_values = Regexp.union(match_array)
I'm using a regex union because the actual ...
0
votes
1
answer
70
views
Applying string functions to Regexp in gsub in Ruby [duplicate]
In Python it's possible to do something like this:
re.sub("_.", lambda match: match.group().upper(), "ab_cde")
This would result in "ab_Cde", since the matched group is ...
1
vote
2
answers
130
views
Regex: Capture only matching alternative in Ruby
I am cracking my head open with this:
I am building a simple password generator which uses a pattern created by the user. The pattern contains the letters a-f which stand for 6 character groups:
So, ...
0
votes
2
answers
62
views
Regular expression to capture the first 4 Numbers from a string [duplicate]
Was playing around with regex to learn it better and wondering if we can write regex to match something like the following use case below
Example String: 1_234_3456_345
Expected result: I want to ...
-2
votes
1
answer
67
views
What does the operator ?: do in a Ruby regular expression when placed immediately after a (, particularly when the regex contains groups? [duplicate]
string = "This is a paragraph with a bunch3c:77:e6:68:66:e9of random MAC addresses 1100:50:7F:E6:96:20hello world 15:00s, 00:50:56:c0:00:08 some other text is written here 00-0C-29-38-1D-61 00:11:...
1
vote
3
answers
95
views
Regex: match string with or without quote
I'm trying to extract a value using regex.
This value can be quoted or not:
For example:
foo: "bar"
or
foo: 'bar'
or
foo: bar
How can I extract only bar value?
Here is the regex I use:
^(...
0
votes
4
answers
100
views
Chop a string in Ruby into max length string considering new line and space characters
I have this long text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum id augue id mattis. Praesent congue nisi quam, ac gravida enim viverra non. Vestibulum id interdum ...
-1
votes
3
answers
111
views
Ruby regex for comma separated unique numbers using negative lookahead
Following is a regex which matches a comma-separated list of numbers and allows only unique numbers to be input:
^(?!.*\b(\d+)\b.*\b\1\b)(\d)(,(\d))*$
For e.g it allows 1,2,3 but disallows 1,1 or 2,1,...
1
vote
2
answers
107
views
Scanning for words in a string with no spaces
I'm trying to extract words from a string in Ruby. For example, if I have this:
"12jdfndjseven456sfjithree"
I want to get an array with ["seven", "three"]. The only words ...
1
vote
3
answers
81
views
regex with letters and number combination
I am trying to create a regex for a format:
TNP-XXXXX
Only the letters TNP and - are allowed and the XXXXX are numbers, it can only accept up to 5 numbers.
Here is what I have so far:
if !(/TNP-[\d]{5,...
0
votes
0
answers
31
views
Replace a String with a Match from a regex in Jekyll [duplicate]
I want to take any Youtube URL and parse out the "code" so that I can imbed or link to the video.
I manged to find the following Ruby:
module Jekyll
module RegexFilter
def ...
0
votes
1
answer
74
views
Disallow character if not prefixed with another character using regex
I have incorporated the following regular expression into my code:
.gsub(/(^|[^*])(\*\*)([^*]+)(\*\*)($|[^*])/m, '\1*\3*\5') # bold
The issue I'm facing is that the \3 block (defined as [^*]+) doesn'...
0
votes
0
answers
70
views
Fluentd error log config file format RegEX
My error:
[warn]: #0 pattern not matched: "Oct 3 17:23:12 dc2prepzeebe03 broker[12925]: {\"severity\":\"DEBUG\",\"logging.googleapis.com/sourceLocation\":{\"...
0
votes
2
answers
160
views
Regular expression for matching 2 numbers (with required decimals) that are separated by at MOST 6 words?
I'm looking to construct a regex that matches 2 decimal numbers (MUST contain a decimal point) separated by at most 6 words (words in this case meaning anything that has a space to the left and right ...