Find a string and extract letter upfront to found string till another specifed string
Tag : regex , By : sadboy
Date : March 29 2020, 07:55 AM
I hope this helps . Since this is a simple substitution on a single line, its a job sed was created to do: $ sed -r 's/.*,[[:space:]]*([^,[:space:]]+)[[:space:]]*Task.*/\1/' file
192
|
How can I find the first non-recurring letter of a string in Ruby?
Tag : ruby , By : CrookedNumber
Date : March 29 2020, 07:55 AM
this will help I have a string "teststring". I want to find first non-recurring character in Ruby. , You could write: str = 'teststring'
arr = str.chars
(arr - (arr.difference(arr.uniq))).first
#= "e"
a = [1,2,3,4,3,2,2,4]
b = [2,3,4,4,4]
a - b #=> [1]
a.difference b #=> [1, 3, 2, 2]
arr - arr.difference(arr.uniq)
|
find letter within string and get positions - ruby
Date : March 29 2020, 07:55 AM
like below fixes the issue The error comes from the fact you haven't closed the range block with an end. But there are other points. I suggest you to try something like this: def nearby_az(str)
list = Array.new
pos = -1
str.each_char do |c|
pos = pos + 1
if (c == 'a') then
list.push(pos+1)
list.push(pos+2)
list.push(pos+3)
end
end
list
end
def nearby_az(str)
list = Array.new
nstr = str.each_char.to_a
nstr.each_index do |i|
if (nstr[i] == 'a') then
list.push(i+1)
list.push(i+2)
list.push(i+3)
end
end
list
end
puts nearby_az("asdfgaqwer")
def nearby_az(string)
list = []
for i in 0..(string.length)
if string[i] == 'a'
list.push(i+1)
list.push(i+2)
list.push(i+3)
end
end
list
end
|
Find and remove from the string words beginning with the letter A
Tag : php , By : m0gb0y74
Date : March 29 2020, 07:55 AM
this will help Suppose I have a string and want to remove all the words that begin with the letter a or A.: , Please use like $string = 'Aorem ipsum adolor sit amet, consectetur dipiscing aelit.';
echo "<br>".preg_replace('/(\ba\w+\b|\bA\w+\b)/', '', $string);
ipsum sit , consectetur dipiscing .
|
find letter at the beginning of the string followed by space
Tag : chash , By : AdrianB
Date : March 29 2020, 07:55 AM
|