Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

pattern memory in javascript

pattern memory in javascript

pattern memory in javascript

I am looking to loop through a file containing lines of such:


The intended logic is if x matches the first number (before the pipe) then set $secondnumberval to the second number (after the pipe).

I've some basic experience with perl. With perl this can be accomplished with simple pattern memory/buffering or splitting. I'm new to javascript and have been unsuccessful in finding anything similar. Any help would be greatly appreciated

RE: pattern memory in javascript

You can use the following regular expression:

var re = /(\d)\|(\d)/
app.alert (re.exec(testString))

This will show you a dialog with the full match and the 2 substrings (the first digit & the second digit).

RE: pattern memory in javascript

Thank you so much, Mark.

In regards to your snippet, can I assign the values of the 2 substrings to independent variables that I can use later?  In perl pattern memory/reference, the first(\d) I could call with $1 and the second with $2.

$bu = "$1";
$fincode = "$2";


RE: pattern memory in javascript

The result of the re.exec() will be an array with the matches (full match, then each substring that was matched)

var re = /(\d)\|(\d)/
var match  = re.exec(testString)
app.alert (match[1]) // First substring
app.alert (match[2]) // Second substring


RE: pattern memory in javascript

Thank you, Mark!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close