I am new to regex and looked into the possible matching expression. But I can't able to find the thing I needed. What I want is remove the word that matches certain expression. The expression is to match all the words ignoring whitespaces, tabs and newline. I am not able to find the correct regex in ruby.
For example:
string = 'hello world welcome'
The thing I need to do is to replace certain words matches with word starting with 'w' and end with 'd'.
string.gsub(/^w.*d$/, 'human')
but I am not able to ignore(escape) spaces(not replacing), tabs and new lines in that.
Can someone help with this. I tried with this below regexp to escape but its not happening.
string.gsub(/^w.*d$\s/, 'human')
'hello world welcome' must be changed to 'hello human welcome' without removing spaces, tabs and newlines in the string.
Is that anywhere I can know more about regexp especially with ruby.
string.gsub(/\b\w[a-z]*d\b/i, 'human') #=> "hello human welcome". You don't want either anchor.^would require'world'to be at the beginning of the line to be matched and hence replaced. Similarly,$would require'world'to be at the end of the line to be matched. The word boundaries,\b(aka "word breaks"). prevent a match if the string were'Hello underworld welcome'and'Hello worldly welcome'./imakes the regex case-indifferent, so it will match, say,'World'.