I'm trying to compare two lists and would like to use regular expression to do just that. Accordingly, I'd like to loop through the elements of one list and compare it to each of the elements in the other list. I can't seem to figure out how to make my regular expression contain a variable. Hopefully, this code should elucidate the matter:
string1="chase"
string2="chasecb"
m=match(r"$string1" ,string2)
println(m)
I know that the $ is a regular expression metacharacter and I've tried escaping it and various permutations of that idea and so forth. Is there another way? Thanks so much.
The cmp() is an inbuilt function in julia which is used to return 0 if the both specified strings are having the same length and the character at each index is the same in both strings, return -1 if a is a prefix of b, or if a comes before b in alphabetical order and return 1 if b is a prefix of a, or if b comes before ...
Using '*' operator It is used to concatenate different strings and/or characters into a single string. We can concatenate two or more strings in Julia using * operator.
Similarly, you can use split() to split the string and count the results: julia> split(s, "") 55-element Array{Char,1}: '/' 'U' 's' 'e' 'r' 's' '/' ...
replace() Method Julia provides an inbuilt replace() function in Julia to replace a word or character with the specified string or character. where its parameters are str1, an abstract string, a pattern that is the word to be replaced, and count, which is of integer type. It returns a new sentence with replaced words.
As jverzani said in a comment, you can use Regex(string1)
or Regex("$string1")
to interpolate into a regular expression, for example:
string1 = "chase"
string2 = "chasecb"
m = match(Regex(string1), string2)
println(m)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With