Reputation: 3920
I have following data
List of devices attached
192.168.56.101:5555 device product:vbox86p model:Samsung_Galaxy_Note_2___4_3___API_18___720x1280 device:vbox86p
192.168.56.102:5555 device product:vbox86tp model:Google_Nexus_7___4_3___API_18___800x1280 device:vbox86tp
from this data i want to search Samsung_Galaxy_Note_
2 and retunn its corresponding 192.168.56.102:5555
how it is possbile using regular expressions
Upvotes: 1
Views: 61
Reputation: 174786
Without any capturing groups and the one through positive lookahead,
^\S+(?=.*?Samsung_Galaxy_Note_2)
Upvotes: 1
Reputation: 41838
At the simplest, you can use this in multi-line mode:
^(\S+).*Samsung_Galaxy_Note_2
and retrieve the match from Group 1. In the regex demo, see the group capture in the right pane.
In JS:
var myregex = /^(\S+).*Samsung_Galaxy_Note_2/m;
var matchArray = myregex.exec(yourString);
if (matchArray != null) {
thematch = matchArray[0];
}
Explanation
^
anchor asserts that we are at the beginning of the string(\S+)
captures to Group 1 any chars that are not white-space chars.*
matches any charsSamsung_Galaxy_Note_2
matches literal charsUpvotes: 2