Regex to identify pattern

Hi
In a file I have string in multiple lines. Like below:

<?=test.getObjectName("L", "testTBL","D") ?> 
<?=test.getObjectName("L", "testTBL","testDB", "D") ?> 

I want to use regex to search for the pattern "<?=test.getObjectName...?>"
If the parenthesis has 3 parameters then return 2nd one.
If the parenthesis has 4 parameters then retrun 3rd&2nd.
So expected output:

testTBL
testDB.testTBL

Thanks in advance
Nitin

Assuming the input is fixed, as you described

awk -F"[, ]" '
 { O=(NF>6)?$4"."$3:$3; gsub("\"", "", O); print O }
' test.txt

testTBL
testDB.testTBL

Try also

sed 's/<?=test.getObjectName("[^"]*",//; s/, *"D") *?>//; s/[" ]//g; s/\([^,]*\),\([^,]*\)/\2.\1/ ' file
testTBL
testDB.testTBL
1 Like

Hi Scott
thanks for prompt reply.
However I am specifically looking for regex as the same code may be executed in unix shell or other languages.

Thanks
Nitin

Good then then RudiC just gave you one :slight_smile: It's not pretty, but they often aren't!

Please be aware that a regex does not "return" anything but only matches something. Those matches may be deleted, substituted, shoved around, whatsoever. My proposal above does all of these.
For your problem, you may need two different regexes, one for either case.