I work with asterisk-11.2.1 I want to use REGEX and wrote this code
${REGEX("^foo$","foo")}
and return 0. Please help me , why 0?
Have you tried with ${REGEX("^foo$" foo)}? Is it work?
Related
I need to declare a string like below
ext = "EXT
But I am not able to achieve it.
I tried below code and it is not worked
ext = '"EXT'
above code giving null only
Please help me
Thanks in advance
You have given extra space before and after the =
The second way which you tried and suggested in other answers will work:
ext='"EXT'
You may try using escape character "" and try something like this :
ext="\"EXT"
ext='"EXT' should work (at least in bash).
You have space between ext and equal sign. That could be a problem.
I have a problem to extract function arguments in R.
x="theme(legend.position='bottom',
legend.margin=(t=0,r=0,b=0,l=0,unit='mm'),
legend.background=element_rect(fill='red',size=rel(1.5)),
panel.background=element_rect(fill='red'),
legend.position='bottom')"
What I want is:
[1]legend.position='bottom'
[2]legend.margin=(t=0,r=0,b=0,l=0,unit='mm')
[3]legend.background=element_rect(fill='red',size=rel(1.5))
[4]panel.background=element_rect(fill='red')
[5]legend.position='bottom'
I tried several regular expressions without success including followings:
strsplit(x,",(?![^()]*\\))",perl=TRUE)
Please help me!
I think the best answer here might be to not attempt to use a regex to parse your function call. As the name implies, regular expressions require regular language. Your function call is not regular, because it has nested parentheses. I currently see a max nested depth of two, but who knows if that could get deeper at some point.
I would recommend writing a simple parser instead. You can use a stack here, to keep track of parentheses. And you would only split a parameter off if all parentheses were closed, implying that you are not in the middle of a parameter, excepting possibly the very first one.
Arf, I'm really sorry but i have to go work, i will continue later but for now i just let my way to solve it partially : theme\(([a-z.]*=['a-z]*)|([a-z._]*=[a-z0-9=,'_.()]*)*\,\)?
It misses only the last part..
Here the regex101 page : https://regex101.com/r/BZpcW0/2
See you later.
Thank you for all your advice. I have parsed the sentences and get the arguments as list. Here is my solution.
x<-"theme(legend.margin=margin(t=0,r=0,b=0,l=0,unit='mm'),
legend.background=element_rect(fill='red',size=rel(1.5)),
panel.background=element_rect(fill='red'),
legend.position='bottom')"
extractArgs=function(x){
result<-tryCatch(eval(parse(text=x)),error=function(e) return("error"))
if("character" %in% class(result)){
args=character(0)
} else {
if(length(names(result)>0)){
pos=unlist(str_locate_all(x,names(result)))
pos=c(sort(pos[seq(1,length(pos),by=2)]),nchar(x)+1)
args=c()
for(i in 1:(length(pos)-1)){
args=c(args,substring(x,pos[i],lead(pos)[i]-2))
}
} else{
args=character(0)
}
}
args
}
Would you somebody please explain it to me, why does str_detect (from the stringr package, ver 1.1.0) return TRUE for each of the three following codes, contrary to my expectations?
str_detect("01", "^[0]*[1-9]*[0]+")
str_detect("01", "^0*[1-9]*0+")
str_detect("01", "^0*[1-9]*0")
I wanted to look for any zeroes at the beginning followed by at least 1 non-zero number and later a zero in the string.
Clearly the "01" string cannot qualify as it does not have a 0 after the 1.
Am I missing something? Is the pattern wrong for what I am looking for?
Thank you for your time!
Since the leading 0 are optionnal in you patterns, they are ignored and the trailing zeros detects the 0 in the string...
Use a $ to specify the end of the string:
str_detect("01", "^[0]*[1-9]*[0]+$")
str_detect("01", "^0*[1-9]*0+$")
str_detect("01", "^0*[1-9]*0$")
I believe you want the following pattern:
^0[1-9]+0
See https://regex101.com/r/v9cwHJ/1 for full pattern explanation.
Your specific error was using * for the first 0, it matches none as well.
Also use + for the second digit to find at least 1.
Can anyone tell me how I can re-write this to compare to greater than rather than equal to:
if (GetSchoolOrLAID.Equals(1))
I want it to be:
if (GetSchoolOrLAID.GreaterThan(1))
Hope really appreciated..
Create an extention method with name as GreaterThan - http://msdn.microsoft.com/en-us/library/bb383977.aspx
Can you not use the operator?
if (GetSchoolOrLAID > 1)
or am I missing something?
How about an operator?
if (GetSchoolOrLAID > 1)
You could use the .Compare() method.
Sample text =
legacycard.ashx?save=false&iNo=3&No=555
Sample pattern =
^legacycard.ashx(.*)No=(\d+)
Want to grab group #2 value of "555" (the value of "No=" in the sample text)
In Expresso, this works, but in ASP.NET UrlRewrite, it is not catching.
Am I missing something?
Thanks!
I would do something along these lines:
^legacycard.ashx\?(?:.+&)*No=(\d+)
The \? will escape the question mark that normally separates the URL and the parameters, then you make sure that it will capture every parameter key/value pair (anything that ends on &) before the parameter you actually care about. Using ?: lets you specify that the set of brackets is non capturing (I'm assuming you won't need any of the data, has the potential to slightly speeds up your regex) and leaves you just 555 captured. The added benefit of this approach is that it'll work regardless of parameter order.
Just use this regex:
^legacycard\.ashx\?save=(false|true)&iNo=(?<ino>\d+)&No=(?<no>\d+)
Then Regex Replace with
${no}
Looks fine to me, your regex should match the entire string
legacycard.ashx?save=false&iNo=3&No=555
not sure why you have groups, but groups should also return
?save=false&iNo=3&
and
555
For good measure you should know that the . in legacycard.ashx is also interpreted by regex and you would normally escape it, in this case it dosen't matter because a single dot matches everything, also a dot. :)
Try this
^legacycard.ashx(\?No=|.*?&No=)(\d+)
this should work.