Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 11 to 20 of 27 total |
Regular Expressions - How to? |
Sun, Sep 11 2016 9:59 PM | Permanent Link |
erickengelke | Trinione wrote:
Erick wrote: << Oops, I didn't see that example. >> >LOL. I can be sure to add it, however my users cannot be trusted to. The closing colon is easier for me to state as well as for them to include. >Thanks for the code. It may come in handy at some point. The TStringList is a super-useful feature. Just maybe not this time. Erick |
Sun, Sep 11 2016 10:07 PM | Permanent Link |
Trinione | Erick wrote:
<< The TStringList is a super-useful feature. Just maybe not this time. >> Which leads me to ask this: How can RegExp be included in EWB? Adding via the External Function is ok, but not having to do this and an external file is preferred. Perhaps Tim can respond regarding inclusion into EWB. |
Sun, Sep 11 2016 10:18 PM | Permanent Link |
erickengelke | Trinione wrote:
Erick wrote: << The TStringList is a super-useful feature. Just maybe not this time. >> >Which leads me to ask this: How can RegExp be included in EWB? Almost anything doable in JavaScript is doable in EWB. My book shows how to call any JavaScript function. It's pretty easy. Personally, I'm not good at Regex. I'd probably look for x := Pos('asd:', s ); if x > 0 then result := Copy( s, x+5,Pos( ':',s, x+5)-1) That's off the top of my head, it may require tweaking. >Adding via the External Function is ok, but not having to do this and an external file is preferred. You don't need external files to declare external functions |
Sun, Sep 11 2016 10:28 PM | Permanent Link |
Trinione | << Almost anything doable in JavaScript is doable in EWB.
My book shows how to call any JavaScript function. It's pretty easy. Personally, I'm not good at Regex. I'd probably look for x := Pos('asd:', s ); if x > 0 then result := Copy( s, x+5,Pos( ':',s, x+5)-1) >> Raul's answer included code that worked perfectly for my use case example. << >Adding via the External Function is ok, but not having to do this and an external file is preferred.>> << You don't need external files to declare external functions >> Raul Wrote: << in your external javascript file add this function function RunRegExec(expr,txt) { var re = new RegExp(expr,"gi"); var execResult; var resultArray = []; while ((execResult = re.exec(txt)) !== null) { resultArray.push(execResult[0]); } return resultArray; } and then declare it as external in EWB external function RunRegExec(expr,txt:string):array of string; >> Are you saying there is no need for an External File? I am really confused? I thought the way Raul described was the way to do it. |
Sun, Sep 11 2016 10:39 PM | Permanent Link |
erickengelke | Trinione wrote:
<< Almost anything doable in JavaScript is doable in EWB. My book shows how to call any JavaScript function. It's pretty easy. Personally, I'm not good at Regex.. <Raul's answer included code that worked perfectly for my use case example. << >Adding via the External Function is ok, but not having to do this and an external file is preferred.>> << You don't need external files to declare external functions >> Yeah, you can do it all in EWB. I put in a bunch of examples, I think more than 50 pages of JavaScript to EWB examples. But I don't personally know the regex stuff well enough to code for it at the top of my head. >Are you saying there is no need for an External File? I am really confused? I thought the way Raul described was the way to do it. His is one way to do it. But EWB translates to JavaScript, once you see a few examples and maybe look at your compiled code, it gets pretty easy to write things in pure EWB. I only use external javascript if it's a big library (like google charts), but for individual routines I just do them in EWB. Erick |
Sun, Sep 11 2016 10:49 PM | Permanent Link |
Trinione | erickengelke wrote:
<< My book shows how to call any JavaScript function. It's pretty easy. >> Fantastic! << Yeah, you can do it all in EWB. ... I put in a bunch of examples, I think more than 50 pages of JavaScript to EWB examples. >> Superb! << His is one way to do it. But EWB translates to JavaScript, once you see a few examples and maybe look at your compiled code, it gets pretty easy to write things in pure EWB. I only use external javascript if it's a big library (like google charts), but for individual routines I just do them in EWB. >> Definitely preferred and with the option to use the External Function when needed - Perfect! Thanks Erick. I shall order the book in a day or two once I arrange non-Amazon related shipping. |
Sun, Sep 11 2016 10:55 PM | Permanent Link |
erickengelke | Trinione wrote:
>Thanks Erick. I shall order the book in a day or two once I arrange non-Amazon related shipping. Sorry I can't help, because shipping to and then from Canada is even more expensive than Amazon's rates. Best have a friend in the US, GB or EU who can get it shipped to them for free. |
Mon, Sep 12 2016 4:45 AM | Permanent Link |
Matthew Jones | Trinione wrote:
> How to get patterns from string? > > For example, 'This is a sample string with AID:123456 in it and > CID:789012.' > > How can I get - AID:123456 and CID:789012? Given the discussion so far, I think it worth mentioning I'd do it with "state machines". Assuming that you have a standard of three letters, a colon, and then digits, you'd just go along the string (from character 4) looking for a colon character. If you find one, then you can look at the previous three characters and check them for validity, perhaps checking that the prior one (if not at first instance) is a space, and then look following it for digits. If the conditions match, add them to the results list, then carry on from where you got to. That's not even really a state machine come to think of it... Quite simple logic set, and will be easier than a regex. -- Matthew Jones |
Mon, Sep 12 2016 5:42 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Matthew
>Given the discussion so far, I think it worth mentioning I'd do it with >"state machines". Assuming that you have a standard of three letters, a >colon, and then digits, you'd just go along the string (from character >4) looking for a colon character. If you find one, then you can look at >the previous three characters and check them for validity, perhaps >checking that the prior one (if not at first instance) is a space, and >then look following it for digits. If the conditions match, add them to >the results list, then carry on from where you got to. That's not even >really a state machine come to think of it... Quite simple logic set, >and will be easier than a regex. You missed out "and faster" If EWB has support for PosEx I'd be tempted to use that. In Delphi somethong like: NextPosition := Pos(':',inputstring); while NextPosition > 0 do begin a bit of code to extract what you actually want NextPosition := PosEx(':',inputstring,NextPosition+1); end; Roy |
Mon, Sep 12 2016 7:29 AM | Permanent Link |
erickengelke | >If EWB has support for PosEx I'd be tempted to use that. In Delphi somethong like:
I'd also be tempted to put a check digit at the end of the number. It would provide a sanity check that the user didn't accidentally delete a digit in the number or insert a digit or some other silly mistake. Credit cards do that and some governmental numbers depending on your country.. Erick |
« Previous Page | Page 2 of 3 | Next Page » |
Jump to Page: 1 2 3 |
This web page was last updated on Thursday, March 28, 2024 at 08:36 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |