Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I want to know if a string includes the form '+#someletter#+', where #someletter# is a
letter. If the string is 'dogs+d+', it would be true because it contains '+d+'. If the string is 'dogs++c', it would be false because the 'c' wasn't surrounded by '+' signs.
I was thinking it was something using regexp like
string.include? '+/a-z/+'
but that doesn't work. Please help.
include? does not accept a regex. To use a regex, you need a different method.
string =~ /\+[a-z]\+/
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm writing a bash script and I want to edit a PHP config file, find a string and replace by another.
The hard part is that I want this search/replace to be dynamic.
Here is an example:
define('APP_VERSION', '1.0.31');
The goal is to replace 1.0.31 by another version number.
How could I achieve that? I've tried with sed, but can't isolate the version number part (because it's not always the same, so I can't directly search for 1.0.31)
Thanks
The point of regexes is to match non-static text. To replace any version number with 123 use
sed "s/define('APP_VERSION', *'[^']*')/define('APP_VERSION', '123')/"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
東京都building千代田区丸の内1building2floor1number
to
東京都千代田区丸の内1-2-1
PS: Digits are double bytes.I have a string,that contains address. How to convert that address like above.
Answering the question that probably should have been asked (given the clarifications in comments):
address.gsub(/([0-9]+)(?:丁目|番地?|号)(?=[0-9]|$)/, '\1-').sub(/-$/, '')
This will process any sequences of "number+location" (with "location" being lot, block, (house) number...) that is either followed by another number, or is at the end of the string, replacing the location with a dash; then removing the final dash, if there is one.
Note that this will not pick up on Japanese numbers: if you get an address like 東京都千代田区丸の内一丁目2番1号, it makes no sense to transform it to 東京都千代田区丸の内一-2-1, and converting Japanese numbers into Arabic ones is trivial up to 9 and then a bit less trivial.
string.gsub(/(?<=[0-9])(?:丁目|番地?|号)\b/, "-").sub(/\z/, "")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
"Galaxy".match(/(al)*/)
It seems that <<>>Galaxy is the match, where <<>> = matching part. Why is the R.E working? Perhaps because of \b?
RE:
Sorry, it's my fault to post unclear question.
Exactly, i want to know the reason that why the empty space is matched with (al)*.
Finally i could understand by you-all favor :)
The regex /(al)*/ allows it to match nothing at all, which is what it does. It starts at the beginning of the string, matches "nothing" and returns. If you expected it to match the al in Galaxy then you would need to use /(al)+/ to avoid empty matches.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need to use scan in particular to get the data and the data only between two values using scan and a regex expression.
The values aren't static so I can't match using them.
Let me rephrase it, i need the value only. So something that allows me to get everything after id="results" value=" and before "
id="results" value="/randompath/lol.jpg"
I got no clue what you're actually searching for but if you want to extract the value of the attribute value in that string (assuming double quotes).
You can use this regex:
(?:^|\s|")value(?:\s+)?=(?:\s+)?(?:"((?:\\.|[^"])+)")
But for sure any html/xml parser like Nokogiri would be better if you can use one.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Eclipse (RedRails) complain about "Feature envy" in the following code:
if input_text =~ /^(---\s*\n.*?\n?)(---.*?)/m
content_text = input_text[($1.size + $2.size)..-1] # warning in $1
header = YAML.load($1)
#content = content_text.strip()
#title = header["title"]
end
My understanding is that I safe to ignore this warning. But I am wandering why this warning is generated. I cannot understand how I can extract method for $1.size and $1.
Reek is telling you that, because you are adding two properties of the same class, the calculation should actually belong in String. When adding string lengths this is nonsense of course, but in your case the code can be simplified by using $& (the complete matched string):
input_text[$&.size..-1]