Using a local variable in regex portion of replaceAll(regex, replacement)

While this works..
output = output.replaceAll("(HED>|AUT>)(.*)(</\\1)", "$1<![CDATA[$2]]>$3");
I'd like the list of alternation values to be contained in a variable, for example:
String nodeLIst = "HED>|AUT>";
output = output.replaceAll("(nodeList)(.*)(</\\1)", "$1<![CDATA[$2]]>$3");
The extension of this would be so I can store this stuff in a db as a list and avoid compilation on change, but please don't let this muddy the waters... :)
Any pointers are much appreciated. Links to specific reading material, etc. I've scoured Friedl's Mastering Regular Expressions to no avail. This approach is supported by some other regex engines I've used (perl, php, ORO?) but I'm new to Java.
TIA,
Mark

I've scoured Friedl's Mastering Regular Expressions to no avail.Did you look on page 209? In the book, that code sample is labelled "Building Up a Regex Through Variables in Java". That should have been a clue. ^_^
But seriously, you're probably thinking of the interpolated strings you find in scripting languages like Perl, PHP, Ruby, etc.. But that's a feature of the language itself, not the regex engine, and Java doesn't work that way. (The $1, $2, etc., in the replacement string are processed by the Matcher class, in a very limited imitation of Perl's variable interpolation).
However, you can fake it pretty well with String's format() method:   String regex = String.format("(%s)(.*)(</\\1)", theAlternation);
  output = output.replaceAll(regex, "$1<![CDATA[$2]]>$3"); That way, you can easily escape the dynamic part, in case it might contain regex metacharacters:   String regex = String.format("(%s)(.*)(</\\1)", Pattern.quote(theAlternation));

Similar Messages

  • No difference between using a local variable and a notifier in timed parallel loops?

    The example code "Pass Data With Notifiers.vi" that came with LV 7.1 illustrates using notifiers with parallel loops.  Just looking at two of the loops, the one that generates the sine wave and the one for "User 1", you can change the timing of the two loops and you can change the condition of the "Ignore Previous" status on the "Wait on Notification".  I have a special case of this to consider, where I'm wondering if there's any reason not to use a local variable instead of the notifier:
    Set the delay on the generator portion (which contains the Send Notification) to something very short, say 5 ms.  Set the delay on the User 1 (which contains the Wait on Notification) to something relatively longer, say 200 ms.  Set the Wait on Notification to False.  Now you have a situation where the User 1 loop action is contingent only upon the loop delay time, since each time the loop timer runs the loop there will always be a value in the notifier.  In this case it seems to behave just like the case where you update a local variable in the fast loop and read it in the slow one.
    Is my understanding correct?  Would there be a performance difference between the two methods?  What do you prefer in this situation and why?
    Thanks,
    Hosehead

    Hi H.,
    I think your idea is to write to a Global Variable in the data-producer VI, and read it in the data-consumer VI(?)
    One reason this might be less efficient than using Notifiers is if you want to graph every new value in the "consumer" - or make sure the value read in the consumer has changed at least once since the last loop.
    > since each time the [consumer] loop timer runs the loop there will always be a value in the notifier...
    > Would there be a performance difference between the two methods? 
    If you don't use the Notification "event" to synchronize the producer and consumer, then to be sure the consumer gets a new vaue, you've made the producer loop faster - every 5 ms - a waste of cpu-cycles.  More often the situation is reversed, that is, there's a consumer that needs to see every single new value, and (without events) the consumer must loop faster than the producer (to catch every new value) - this is called polling and it wastes cpu-cycles.
    Just about anytime one's tempted to make a loop execute "fast" to check on some value (or to make sure there's a fresh value,) there's an opportunity to improve performance through synchronization with events (including notifiers, queues, occurrances, semaphores, and rendezvous')
    tbd
    Message Edited by tbd on 07-09-2006 03:51 AM
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)

  • Store Counter Number in BODS using Global/Local Variable

    Hi All,
    Anyone done before adding a counter integer field into a table based on key via BODS?
    Example:
    Table 1 (contains just 1 field) <-Input:
    Key 1
    Key 1
    Key 2
    Key 2
    Key 2
    Table 2(contains 2 fields with INT as the 2nd field) <-Output:
    Key 1      1
    Key 1      2
    Key 2      1
    Key 2      2
    Key 2      3
    I was wondering if populating the Local Variable or Global Variable might work but from my understanding, inside the Data Flow , it's not possible to increase the variable value ($count = $count + 1).

    Hi Maurice,
    Thats a good idea!!
    I had currently implemented a solution where i use Variables and Customize Functions to solve the problem.
    Will give a try and see if your solution produce the same result.
    Tim

  • I want to fill and empty a tank automatically can this be achieved without the use of local variables?

    Gurus of Labview,
    I have a Project to complete and i am new to labview, I have student version 2009. and want to build an initial vi of a Municipal water trteatment plant TO FILL AND EMPTY TANKS. I am using the DSC module to help and I can get my tanks to complete a sequence, however it uses local variables. They cannot be shared on the network when I create my libraries.  Need help urgently..
    Casey74
    Solved!
    Go to Solution.

    Casey74 wrote: 
    Here is the block diagram for your enjoyment.......
    Sorry, I cannot "enjoy" an image. It would help much more to see the actual VI.
    LabVIEW Champion . Do more with less code and in less time .

  • How to use local variable in member formula?

    Hi Expert,
    We would like to use a {local variable} in a member formula, so that it can pick up the prompt from webform upon save. Would like to know if it is possible to do? If so, what is the correct syntax?
    We attempted to use brace {scenario}, blacket [scenario], blacket with quote ["scenario"]. None of these work.
    We are using 11.1.2.1 version, EPMA, Hyperion Planning.
    Thanks in advance for your help!

    One other pointer. Where did you define your variable? Hopefully you went into Calc Manager and selected <Tools>, <Variables>. From there, navigate to your application or database. Right-click on your application or database and select "New". In the bottom panel, you'll need to select your Variable Type. Make sure you select "Member", and not "Members". You cannot pass "Members" (plural) to a web input form. Also, if you want to define a variable for a custom dimension, you'll need to do it at the database level. Standard dimension member variables can be defined at the app level. (Not sure why this is the case, especially when my custom dimension exists in all plan types . . . . )
    Anyway, hope this helps,
    - Jake

  • Problem using local variable in event loop

    I have a state machine from which I want to monitor various controls, including "Start" and "Stop" buttons.  Not every state needs to monitor the controls.  At present, most states run timed loops.  In the first state that reads the front panel, I have an Event structure (inside a While loop) that monitors the various controls' Change Value events.  For numeric controls, I update variables (in shift registers) as needed.  The "Start" button is used to end the While loop controlling the Event structure, allowing the State to exit to the next state.
    My problem comes in subsequent states that employ this same idea.  Here, I put a Local Variable bound to the Start button and use the same code, but it frequently happens that when I enter this particular state, I cannot "turn on" the control -- I push the button, but it stays off.  Curiously, if it was On when I enter, I can turn it off, but then I'm stuck not being able to turn it on.
    I mocked up a very simply routine that illustrates this.  There are two sequences (corresponding to the two states).  Both use an Event loop with a local variable bound to my Stop button (really this is an LED control with custom colors).  I've deliberately moved the "initialization" (the declaration of the control in the block diagram) out of the Event loops -- putting it inside the first loop modifies the behavior in another strange way.
    Here's my thinking on how I would expect this to work:  The code outside Event Loop 1 should have little effect.  Assume the Stop button is initially Off.  You will "sit" in Event Loop 1 until you push the Stop button, changing its value to True; this value will be passed out of the Event case and cause the first While loop to exit.  You now enter the second sequence.  As I understand the Exit tunnel, it defaults to "False", so I'd expect to stay in the second Event loop until I turn the Stop button from On to Off, which will pass out a False, and keep me in the While for one more button push.  However, this doesn't happen -- I immediately exit, as though the "True" value of the Stop local variable is being seen and recognized by the Event loop (even though it hasn't changed, at least not in the context of this second loop).
    An even more curious thing occurs if I start this routine with the Stop button turned on.  Now I start in my Event loop waiting for a change, but this time the change will be from On to Off, which won't cause an exit from the frame.  This will be reflected by having the While loop count increment.  We should now be in the state of the example above, i.e. in an Event loop waiting for the control to be pushed again, and turned On.  However, clicking the control has no effect -- I cannot get it to "turn on".
    Where am I going astray in my thinking?  What is it about this method of doing things that violates the Labview paradigm?  As far as I can tell, what I'm doing is "legal", and I don't see the flaw in my reasoning, above (of course not -- otherwise I'd have fixed it myself!).  Note that because I'm using local variables inside Event loops (and I'm doing this because there are two places in my code where I want to do such testing), the Stop control is not latching (as required).  Is there something that gets triggered/set when one reads a latched control?  Do I need to do this "manually" using my local variable?
    I'll try to attach the simple VI that illustrates this behavior.
    Bob Schor
    Attachments:
    Simple Stop Conundrum.vi ‏14 KB

    altenbach wrote:
    Ravens Fan wrote:
    NEVER have multiple event structures that share the same events. 
    Actually, that's OK.  NOT OK is having multiple event structures in the same sequence structure.
    See also: http://forums.ni.com/ni/board/message?board.id=170&message.id=278981#M278981
    That's interesting.  I had always thought I read more messages discouraging such a thing rather than saying it was okay.  Your link lead me to another thread with this message. http://forums.ni.com/ni/board/message?board.id=170&message.id=245793#M245793.  Now that thread was mainly concentrating on registered user events which would be a different, but related animal. 
    So if you have 2 event structures they each have their own event queue?  So if you have a common event, one structure pulls it off its event queue and it does not affect the other structure's event queue?  I guess the inherent problem with this particular VI was that the second event structure locked the front panel.  Since the code never got to that 2nd event structure because the  first loop never stopped because the change was from true to false.  After reading your post and the others, I did some experimentation and turned off the Lock front panel on the 2nd structure, and that prevented the lockup of the program.
    Overall, the example VI still shows problems with the architecture and I think your answer should put the original poster on the right track.  I think as a rule I would probably never put the same event in multiple structures, I feel there are better ways to communicate the same event between different parts of a program,  but I learned something by reading your reply and about how the event structures work in the background.  Thanks.

  • Local variable fail when using SIT

    Dear all,
    I am using SIT (Simulink Interface Toolkit) to obtain data generated by the model of  Simulink.  I need to use the local variable of the indicator to get the data out.
    The interface with the mappings seems to work fine. The problemn is that the local variable of the waveform (this waveform is an indicater which mapped to the output signal of simulink and it can displays the signal from simulink)didn't work. I cann't obtain any data from the local variable, but the waveform which the local variable belonges to seems to work fine.
    I also found an interesting thing that, when I hightlighting the execution process, the local variable  seems like didn't work at all, because there is no data flows from it.
    The software version is Matlab simulink R2011b, Labview 2011.
    Below is a simple test model in simulink. It is a sine signal.
    Below is the local variable from the waveform which mapped to the signal of simulink. To check there is any data in the local variable, I put a waveform to check.

    Dataflow.
    The local variable of the waveform is going to be empty to start.  The writing of the local variable called Waveform to the indicator called Local Variable is going to happen right away.  Only later does the waveform get any data.  But by then the first part has already exectued never to be run again.
    I would recommend looking at the online LabVIEW tutorials
    LabVIEW Introduction Course - Three Hours
    LabVIEW Introduction Course - Six Hours

  • Using local variables to "clean up" diagram

    I have attached a photo with red circles indicating my use of local variables to "clean up" a block diagram. Would I run into any issues doing this? Can I leave this task and error unwired?
    -Sarah
    Solved!
    Go to Solution.

    I see some possibly really bad race conditions with your VISA Resources.  For instance, if Task Out 3 is empty (by default), it is likely that the local to read will happen before the local to write.  What this will turn into is you loosing your VISA Reference in the shift register.  Use wires.  Locals very rarely clean up your diagram.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions

  • Does a large amount of "local variable" within a vi cause problems?

    Hello -- I am using Labview 7.0 and have a vi where I am going to end up using about 100 "local variables" for indicators that are displaying data. Since I have a lot of true / false case structures I decided to use these local variables instead of having a mess of wiring all over the vi block diagram. It is intimidating though and I was wondering if it causes slowness in vi's?

    I actually only have about 8 indicators -- but I am in the process of creating control algorithms so I have to use many case structures if I want to keep the code all within Labview (simplicity). I am simply referencing the 8 or so indicator values many many times (100 X) I am attaching a copy of the vi like you asked but just take a look at the right hand side of the while loop on the right -- it shows an example of an algorithm I created today that has to reference the data from sensors. I would love to know what a better way to do this. Thanks!
    Attachments:
    ucb drill control daq 1_7.vi ‏666 KB

  • How come my local variable is not updating it's value with respect to what's happening in the while loop?

    Hello,
    I am trying to extract data out of a while loop as my declarations update with respect to the iteration number. I have attempted to use both local variables and shift registers, but with no luck.
    I have also done the following example: http://www.ni.com/white-paper/7585/en and it works like a charm.
    I attached the PNG file with local variable declaration circled in red. Will attach a VI in the next respnose.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Local Variable.png ‏366 KB

    OK, looking at the code...
    Can you explain what it is supposed to do? What's the purpose of the value property node read which only seems to update an indicator.
    The inner while loop should proably be a FOR loop, because the number of iterations is known before the loop starts.
    Your use of formula nodes seems overly complicated.
    LabVIEW Champion . Do more with less code and in less time .

  • Issue with local variable in forms personalization

    Hi All,
    I did the following things at last it is give me syntax error, please help me on this.
    Rules section:
    seq Description Level Enabled
    1 Populate Number Function y
    Conditions:
    T.E : When new item instance
    T.O : REQ_LINES.REQUISIOTN_NUMBER
    Condition::REQ_LINES.BLANKET_PO_NUM_DSP IS NOT NULL AND
    :REQ_LINES.SELECT_LINE='Y'
    Processing mode: Not in enter query mode
    Actions:
    seq: Type: Desc: Langauge: Enabled
    1: property: local variable :Y
    Object Type: Local Varibale
    Target Object: XXNUM
    property : Value
    Text: = TO_CHAR(${item.req_lines.blanket_po_num_dsp.value})
    Rules section:
    seq Description Level Enabled
    1 Default Number Function y
    Conditions:
    T.E : When block instance
    T.O : New_DOCUMENT
    Condition:
    Processing mode: Not in enter query mode
    Actions:
    seq: Type: Desc: Langauge: Enabled
    1: property: use of local variable :Y
    Object Type:ITEM
    Target Object:NEW_DOCUMENT.DOCUMENT_NUMBER
    property : Value
    *Text:  = SELECT TO_CHAR (${var.XXNUM.value}) from dual*
    The line which i bold shows me an syntax error, please check the syntax and if it is wrong please correct it.
    Thanks and Regards
    Zaheer
    Edited by: zaheer on Feb 10, 2010 11:25 PM
    Edited by: zaheer on Feb 10, 2010 11:25 PM

    Hi Zaheer,
    Try using this:
    Actions:
    seq: Type: Desc: Langauge: Enabled
    1: property: use of local variable :Y
    Object Type:ITEM
    Target Object:NEW_DOCUMENT.DOCUMENT_NUMBER
    property : Value
    Text: = ${var.XXNUM.value}
    PS: You might get a message while validating, but you can ignore that.
    Regards,
    Sujoy

  • Can I reference a sequence object by a local variabl?

    Hi,
    I create ten sequences in database. In my form, I get a sequence number from different sequence object according to different situations.
    So can I choose one of the seuqences by refering it using a local variable ? such as :
    declare
    first_sequence varchar2(100);
    new_po number(10);
    begin
    first_sequence:='po_number';
    select first_sequence.nextval
    into new_po
    from dual;
    end;
    Thanks
    Stephen

    I cannot see this working as it will complain at compile time. The compiler will look for the envVar as an object on the DB. I believe what you need is something like DBMS_SQL or EXECUTE IMMEDIATE to do what you want.

  • Memory (RAM) model in Flex or ActionScript for local variables in a method

    I have a method in AS3 to handle certain event generated from some Components in <mx:Repeater>. Two different Components can fire the same event
    at the same time so the same method must handle the two events together. My question is if the two calls on the same event handler method will step on each other. The event handler method only uses the local variables.
    In Java, the local variables of a method for the two callers are in two different memory (RAM) addresses. So they will not step on each other. Not sure about
    Flex/ActionScript.

    Actionscript runs in a single thread.  One of the events will get fully
    processed before the other.

  • How to make chart from multiple loops without local variables

    Hi,
    It is my first experience in LabView.
    I did a program that communicate with Power Supply Device via RS232, sets an output voltage and read Voltage and Current in some sort of a program: Voltage goes up, staying in some value and then goes down. So there are many FOR LOOPS that sequensed one after another.
    I need to make a 2 live Charts (one for current and second for voltage), and the only one solution that i could obtain is using local variables. BUT also I need to export my data to the file after the end of the program (with real elapsed time for collecting data points) and with the use of local variables I cannot do so. Maybe the Shift Register will work, but I could not make it work.
    Thank you for help.
    Attachments:
    test.vi ‏47 KB

    You have multiple, deeply stacked, sequential loops. Way too complicated.
    All you need is a simple state machine architecture using a single loop and a single instance of your charts. No local variables needed. Simplify!!! You could even graph both values on a single chart.
    Look at your code. It is basically repeating the same thing with slighly different inputs. You only need to change the inputs based on state, and re-use the same IO function instances. Only one instance each needed.
    (you also have some misguided autoindexing near the middle of your code. Bad!)
    LabVIEW Champion . Do more with less code and in less time .

  • Best way to remove local variables

    Hello,
    I have been told that I need to remove all the local variables in my VI, because they are slow.  I can not seem to find a good option for replacing them but keeping the same functionality.
    What I am using the local variables for is to update 3 different graphs on the front panel from 3 different sources.  Each of these sources are located in while loops so that data can be acquired asynchronously.  In closing these 3 while loops is a case statement.  The case statement is for switching between acquiring and saving the data or just acquiring data.  The local variables are used to update the indicators and graphs from the acquiring and saving data case.  It is these local variables that I need to remove.
    Does anyone have any suggestions?
    -- Z

    Zurvan wrote:
    I have been told that I need to remove all the local variables in my VI, because they are slow.
    Who told you that?
    As others have said, local variables typically don't cause slowdown (They cause additional datacopies in memory, have the potential of causing race conditions and cause messy code).
    What is "slow" in your definition? (missing data, cannot keep up with the instrument, slugging UI, etc.).
    What is the CPU use when your program runs?
    So apparently you have a loop that updates all indicators from local variables. What is the loop rate of that display loop? Do you spin that millions of times per second or pace it at a reasonable rate? How much data is in the graphs?
    Remember, a graph does not need to update unless the data changes.
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for