in Education by
I need to replace each character of a regular expression, once evaluated, with each character plus the @ symbol. For example: If the regular expression is: POS[AB] and the input text is: POSA_____POSB I want to get this result: P@O@S@A@_____P@O@S@B@ Please, using sed or awk. I have tried this: $ echo "POSA_____POSB" | sed "s/POS[AB]/&@/g" POSA@_____POSB@ $ echo "POSA_____POSB" | sed "s/./&@/g" P@O@S@A@_@_@_@_@_@P@O@S@B@ But what I need is: P@O@S@A@_____P@O@S@B@ Thank you in advance. Best regards, Octavio JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Perl to the resuce! perl -pe 's/(POS[AB])/$1 =~ s:(.):$1@:gr/ge' The /e interprets the replacement as code, and it contains another substitution which replaces each character with itself plus @. In ancient Perls before 5.14 (i.e. without the /r modifier), you need to use a bit more complex perl -pe 's/(POS[AB])/$x = $1; $x =~ s:(.):$1@:g; $x/ge'

Related questions

0 votes
    I need to replace each character of a regular expression, once evaluated, with each character plus the @ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am reading some equipment configuration output and check if the configuration is correct, according to the ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I am reading some equipment configuration output and check if the configuration is correct, according to the ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    ‘ptr’ is a pointer to a data type. The expression *ptr++ is evaluated as?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    I switched from Perl to Python about a year ago and haven't looked back. There is only one idiom ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I switched from Perl to Python about a year ago and haven't looked back. There is only one idiom ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    How will you convert a object to a regular expression in python?...
asked Nov 24, 2020 in Technology by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I hope this is programmer-related question. I'm in the hobby business of C# programming. For my own ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    What is the significance of Matcher class for regular expression in java? (a) interpretes pattern in the string ... Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Object of which class is used to compile regular expression? (a) Pattern class (b) Matcher class (c) ... Regular Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which of the following matches nonword character using regular expression in java? (a) \w (b) \W (c) \ ... Regular Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
...