Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


Jaden856

4 posts

Wannabe Geek


#302285 12-Nov-2022 22:29
Send private message

Hi

 

 

I'be been following some linux basics and am stuck with 4 exercises around expressions

 

 

 

1.Match this string at the end of a line: EOF$

 

solution ******

 

I tried

 

$EOF\$

 

$EOF\W

 

 

 

2. Match all lines that start with $, followed by any single digit,

 

followed by $, followed by one or more non-whitespace characters

 

 

solution *********

 

I tried $\$\d\s+

 

 

3. Match all of these emails while also adding the username and the domain name (not the TLD) in separate groups (use \w): hello@tryhackme.com, username@domain.com, dummy_email@xyz.com

 

solution ************.***

 

I tried \w{4-11}@\w+.com

 

 

4. match every possible IPv4 IP address (use metacharacters and groups)

 

solution ***{*,*}*.*{*}**{*,*}

 

 

Thanks for any tips :)

Create new topic
fe31nz
1294 posts

Uber Geek
+1 received by user: 423


  #2995231 12-Nov-2022 23:42
Send private message

There are many different types of regular expressions.  So the first thing is to know what program is being used and what type of regular expressions it uses.  Is it POSIX basic, POSIX extended, Perl, PCRE, Brief, Slickedit, ....  The most common type is POSIX basic, which is what most decent versions of grep use.  If you use the -E option in grep, then you are likely using POSIX extended.  Perl itself and quite a number of other programs use Perl regular expressions.  For example, Python uses a variant of Perl regular expressions in its "re" module.




surfisup1000
5288 posts

Uber Geek
+1 received by user: 2159


  #2995235 12-Nov-2022 23:59
Send private message

first one....

 

EOF\$$

 

2nd one. 

 

^\$\d\$\S+

 

 


yitz
2239 posts

Uber Geek
+1 received by user: 594


  #2995343 13-Nov-2022 03:28
Send private message

\ a backslash escapes literals like an actual dollar sign character

 

^ caret for matching beginning of line

 

$ dollar for matching end of line

 

square brackets denote groups e.g. [a-z] means all lowercase letters of alphabet [0-9] means all digits 0-9 or a combination [a-zA-Z0-9] or use metacharacters  [\w] all word metacharacters [\d] all digits

 

+ matching one or more occurrences of previous character
* matching zero of more occurrences of previous character
curly braces specify the number of matches (or a range) of the previous character/group of characters

 

Hope this helps without giving away too much...




shaned
22 posts

Geek
+1 received by user: 2


  #2995967 14-Nov-2022 12:54
Send private message

Your attempted answers are a little puzzling. I think there may be some fundamental misunderstanding. Perhaps rather than us simply providing solutions, would you mind trying to explain your reasoning behind your answers? I suspect you've absorbed some bad info, and if we can see where you're going wrong, we may be able to get you back on the right track quickly.

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.