Tagged Questions
0
votes
5answers
39 views
String gsub - Replace characters between two elements, but leave surrounding elements
Suppose I have the following string:
mystring = "start/abc123/end"
How can you splice out the abc123 with something else, while leaving the "/start/" and "/end" elements intact?
I had the ...
0
votes
3answers
38 views
Get youtube video id from html code
I have html like this
<iframe width="560" height="315" src="http://www.youtube.com/embed/Wa6CA3YqV2Q" frameborder="0" allowfullscreen></iframe>
How do i get video id Wa6CA3YqV2Q with ...
0
votes
3answers
39 views
Getting each instance of matched string from MatchData
I am using a scan function with a regex that returns the following objects. The result of the scan is assigned to a h.
When I call h[0] however I only receive one instance of somedata1 even if occurs ...
1
vote
2answers
44 views
regex that returns matches of a range in length and containing one of several words in Ruby
I tried the following regex in Ruby:
"the foodogand the catlada are mouseing".scan(/\b(?=\w{6,12}\b)\w{0,9}(cat|dog|mouse)\w*/)
but instead of it returning
["foodogand", "catlada", "mouseing"]
...
0
votes
8answers
55 views
Insert characters at end of filename (before extension)?
I have image files that I want to append a string to the name of the file, right before the extension.
Example: example.png would turn in to example-2x.png
So, I want to insert -2x right before the ...
0
votes
3answers
40 views
get groups of characters n at a time
I'm trying to group a string by three (but could be any number) characters at a time. Using this code:
"this gets three at a time".scan(/\w\w\w/)
I get:
["thi","get","thr","tim"]
But what I'm ...
3
votes
3answers
50 views
Replace every other character
how could i skip or replace every other character (could be anything) with regex?
"abc123.-def45".gsub(/.(.)?/, '@')
to get
"a@c@2@.@d@f@5"
0
votes
2answers
30 views
What would the regex be to detect this string?
I need to determine if a given string has the sequence dash-alpha-alpha-dash.
Example strings:
114888-ZV-209897
409-II-224858
86296-MO-184080
2459-ND-217906
What would be the the regex to ...
1
vote
1answer
21 views
Regex flatten usage
I am using regex to extract a value from a variable. The output comes in this format:
[["\"XXX.YYY\""]]
So, I use flatten & it gives me this output:
["\"XXX.YYY\""]
How can I extract only ...
0
votes
3answers
49 views
How do I replace portions of a string which have a specific format?
I am working on my Rails application in which I've implemented mentions using the jQuery autocomplete plugin.
This is an example string containing mentions when an update is submitted:
-> Hello ...
1
vote
1answer
39 views
Extracting value from stdout of Open3.popen3 through RegEx and store it
I'm fairly new to Ruby and can't seem to find a way of getting the output of an external command. I need to extract values returned by the command. For now I have something like this:
stdin, stdout, ...
4
votes
4answers
63 views
Splitting string in Ruby on list of words using regex
I'm trying to split a string in Ruby into smaller sub-strings or phrases based on a list of stop words. The split method works when I define the regular expression pattern directly; however, it ...
-3
votes
1answer
20 views
Regex on gskinner doesn't work on Rubular [closed]
The following regular expression works fine through gskinner's form, but does not detect the same string on rubular. Any idea what parts have to be translated for use with Ruby:
...
0
votes
1answer
55 views
What does this regex `str.gsub(/\#{(.*?)}/)` do?
.* means any character, so why is the .*? needed in the following?
str.gsub(/\#{(.*?)}/) {eval($1)}
5
votes
4answers
87 views
what is equivalent of =~ of ruby in php?
I am a Rubyist trying to implement some of my code in PHP and not able to get the equivalent PHP code for this particular def.Can anyone help me out.Thanks in advance.
def check_condition(str)
str ...