Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] regex makes no sense. example doesn't work
#1
Hi,

I've tried to figure this out for the past two hours and I can't take it anymore. I don't get this at all.

<!--987987-->

I'm trying to get the result, 987987 - basicaly the stuff in the middle.

regexpattern =
;<!--(.*)-->

I tried changing the pattern to just --(.*)--

tempvar is str that holds data to search
uniqueidcode I tried to declare this a str and int. neither works.

if(0=findrx(tempvar regexpattern uniqueidcode)) end "not found"

when this works it spits out a single character. Most of the time it gives us me 0.

Thanks for reading.

ps I did read the help file. I did try the example and I can't make that work either. I googled and it suggested the same solution.

Find digits (10)
str subject="abc10 100 def"
out findrx(subject "\d+")

That outputs a single digit - the position of the first digit. I expected this to output all digits.
#2
Macro Macro1
Code:
Copy      Help
str subject="<!--987987-->"
ARRAY(str) result
str regx="<!--(.*)-->"
if(findrx(subject regx 0 0 result)>=0)     
,out F"result: {result[1]}" ;; output '987987'


;; ARRAY(str) result receives the match in element 0
;; and submatches in subsequent elements.
;; this means 'result[0]' will contain: '<!--987987-->'
;; everything above '0' will contain the submatches, this means:
;; 'result[1]' will contain '987987'

;; A submatch is the part of the match that matches a captured subpattern.
;; A captured subpattern is the part of pattern that is enclosed
;; in parentheses and does not begin with ?.

I think this can get you started.
#3
if(0=findrx(tempvar regexpattern uniqueidcode)) end "not found"
Your Findrx statement is incorrect that is why it doesn't work



Function Function
Code:
Copy      Help
str tempvar regexpattern uniqueidcode
tempvar="<!--987987-->"
regexpattern="\d+"
findrx(tempvar regexpattern 0 0 uniqueidcode)
out uniqueidcode

to see the proper code needed for a function left click the function name in the editor window and look at the bottom in the status bar to see the syntax needed
#4
Thank you both. It's such a relief to finally see it working.


Forum Jump:


Users browsing this thread: 1 Guest(s)