Search code examples
regexperlunixpattern-matchingregular-language

Regular Expression in Perl to check fit/match


I'm in great trouble.

I must check if a string fits (matches) another string with RegEx. For example, given the following string:

Apr 2 13:42:32 sandbox izxp[12000]: Received disconnect from 10.11.106.14: 10: disconnected by user

In the editable input field I give the program the following shortened string:

Received disconnect from 10.11.106.14: 10

If it fits the existing string (as you can see above), it is OK. If any part of the new edited string doesn't fit the original string, I must warn the user with a message.

Could you help me solving this question with RegEx? Or another method? I would appreciate it!


Solution

  • You must get the original string in a variable, let's call it $original (this is perl). Then you must get the input from the "editable input field", let's call it $input.

    Then it is a simple

    if ($original=~/$input/)
    {
       #Your code for a message to the user here 
    
    }