Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3305158
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:08:17+00:00 2026-05-17T21:08:17+00:00

Maybe someone have idea for perl script with very strong irregular expression that match

  • 0

Maybe someone have idea for perl script with very strong irregular expression that match only lines with uniqe rule ( [param_name] [separator] [any_value] )

Rules described in EXAMPLE1 and EXAMPLE2

The target of the script is to match the Valid Lines, described below (EXAMPLE1 – VALID lines and ignore the non valid lines described in EXAMPLE2 – non valid lines)

I will be glad if someone have a brilliant code that match the valid lines from file and
print the valid lines in to /tmp/Valid.txt
And print the non valid line in to /tmp/nonvalid.txt

Example how to run the script

./find_valid_lines.pl   file

Definition:

Valid line syntax:

[Parameter_name] [separator] [Value]

where:

  • Parameter_name: any string. but not number. or string that start with number/s
  • separator: is the “=” character (only one seperator each line)
  • Value: any string or number or character include Exceptional characters
    as $ * & ( _ { [ ‘ ” ? < ~ ! and so on

But in case the line has the ; character, the script must take the line until ; only if line before ; is a valid line.

For example:

 MY__param = 100 ; 1000

Then

 MY__param = 100 
  • Remark: the script will ignore the line if “#” char exist in the line beginning

Examples of lines in files (valid lines – example1 and not valid lines – example2)

EXAMPLE1: Valid Lines (Valid parameter & Valid separator & Valid value)

 parameter=1 
 parameter.1=1 2 3
 MY_Name.2= A B C
 parameter =1 * * $ @
 Home_NAME =MOON
 param1=1 2 3 + * *
 Param_A = 73826.32863
 PARAM_STAR    =   23.84 (2.d) 12 & {0} (8) 100%
 Param120A = ~1.33454656
 @param =90%
 P1= -39546
 My_param=#
 My_P = # #123
 MY_Parameter =   <34> 2 3 4 5 6 7 8 9 A "ededefec" $100
 uniq_param=?
 T = 0
 GH.@=%
 PORT_NUM= 123 / 98775 /  554 / 34545 / 54
 ADDRESS  = 172.19.0.1
 FolderHome     = /dir746/dir87/file1 , /dir746/dir87/file2
 switch_from_LAN*=100G_SPEED

EXAMPLE2: Non Valid Lines (Non Valid parameter OR Non Valid separator OR Non Valid value)

 PARAM== 100
 Param = 276 =
 276 = 2652
 = 234
 Name = 
 PARAMETER = ;
 Param_is_file 123
 port 19463
 David_name
 243546
 =
 635A
 10Param
 *&^
 = &^#$>:
 A 123
 65MY_PARAM_NAME=10
 all_strings=; 75845
 switch_from_LAN*=
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:08:17+00:00Added an answer on May 17, 2026 at 9:08 pm

    Here is one way:

    #!/usr/bin/perl
    
    use strict; use warnings;
    use File::Slurp;
    
    while ( my $line = <DATA> ) {
        my $save = $line;
        $line =~ s/\s*;.*\z//s; # ignore comments
    
        my ($p, $v) = map { s/^\s+//; s/\s+\z//; $_ } split /=/, $line, 2;
    
        if ( defined($v) and $p =~ /^[^0-9].*\z/ and $v =~ /^[^=]+\z/ ) {
            append_file 'valid.txt', \ $save;
        }
        else {
            append_file 'invalid.txt', \ $save;
        }
    }
    
    __DATA__
    parameter=1
    parameter.1=1 2 3
    MY_Name.2= A B C
    parameter =1 * * $ @
    Home_NAME =MOON
    param1=1 2 3 + * *
    Param_A = 73826.32863
    PARAM_STAR    =   23.84 (2.d) 12 & {0} (8) 100%
    Param120A = ~1.33454656
    @param =90%
    P1= -39546
    My_param=#
    My_P = # #123
    MY_Parameter =   <34> 2 3 4 5 6 7 8 9 A "ededefec" $100
    uniq_param=?
    T = 0
    GH.@=%
    PORT_NUM= 123 / 98775 /  554 / 34545 / 54
    ADDRESS  = 172.19.0.1
    PARAM== 100
    Param = 276 =
    276 = 2652
    = 234
    Name =
    PARAMETER = ;
    Param_is_file 123
    port 19463
    David_name
    243546
    =
    635A
    10Param
    *&^
    = &^#$>:
    A 123
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm betting that someone has already solved this and maybe I'm using the wrong
Maybe someone found a workaround for the following problem: It seems as if AXIS
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Maybe I just don't know .NET well enough yet, but I have yet to
Maybe this applied to other Delphi's (I've only used 7). We've got our code
Maybe the need to do this is a 'design smell' but thinking about another
Maybe this is a dumb question, but is there any way to convert a
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
Maybe my understanding of agile development isn't as good as it should be, but
Maybe this is an overarching question as I've seen similar bugs in Firefox and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.