Can you solve this puzzle involving regular expressions?

In summary, the puzzle asks to find a line that matches each of the regex strings. The first line matches a string containing the text security. The second line matches a line where the 4th character is an s and some more s later on. The first attempt yielded the sentence but it doesn’t match all the criteria. The second attempt yielded the but it doesn’t match all the criteria.
  • #1
MesonMarcus
2
0
can anyone help solve this puzzle regarding regular expressions? I was given this in an interview test from BAE systems cyber security department a few years ago and just came across it again, still haven't managed to get anywhere like an answer. I have tried matching each line of regex to form words but no look. The puzzle is as follows:
unnamed.png


.{14}security.{15}
[^s]{3}s [^s]{6}s[^s] s[^s]{12}s [^s]{8}
def
^It'..[ywkni][klmop][zwta]
ce.$
jus
[^f]*fenc
y, it's
t ...t

Give your answer.

This is the best I could get...

...security...
bees xxxxxxsx sxxxxxxxxxxxxs xxxxxxxx
def
It's not
ce.
jus
xfenc
y, it's
t xxxt

but makes no sense...
 
Physics news on Phys.org
  • #2
The idea is to find a line that matches each of the regex strings.

[^x] means doesn’t match x and

{99} is the number of times to match with * for 0 or more and + for one or more.

^ outside of the [ ] means beginning of the string and $ means the end of the string.

I think the first line matches a string containing the text security

. . . . . . . . . . . . . . s e c u r i t y . . . . . . . . . . . . . . .

the second line matches a line where the 4th character is an s and some more s later on.

I t ‘ s . n o t . . . . . . s e c u r i t y . . . . . . . . . . . . c e .

my attempt yielded the sentence but it doesn’t match all the criteria.

I T ' S _ N O T _ J U S T _ S E C U R I T Y , _ I T ' S _ D E F E N C E .
 
  • Like
Likes pbuk
  • #3
awesome!
 
  • #4
jedishrfu said:
I T ' S _ N O T _ J U S T _ S E C U R I T Y , _ I T ' S _ D E F E N C E .
It's not just security, it's defence. works for me.
 
  • #5
I had trouble with line 2 aka the s not s expression. It seemed not all the ‘s’ characters lined up in my solution although I didn’t test it.

I ll have to try it in AWK, my favorite go to language.
 
  • #6
jedishrfu said:
I had trouble with line 2 aka the s not s expression. It seemed not all the ‘s’ characters lined up in my solution although I didn’t test it.
Line 2 only depends on 's's and spaces in the right place. It won't match if you use the US spelling for defence, unsurprisingly given the employer :biggrin:
 
  • #7
But it seemed solving it on paper that a couple of s characters were off According to that regex. I chalked it up to the possibility that the expression was an outlier perhaps designed to be misleading ala obfuscation Aka security thru obscurity.

I as puzzled by the defence spelling too but decided that since BAE is a British company that the spelling was correct. I imagine that would have tripped up a few Americans applying for the job. :-)
 

1. How do regular expressions work?

Regular expressions, also known as regex, are patterns used to match character combinations in strings. They are used for searching, replacing, and validating data in various programming languages.

2. What are the basic components of a regular expression?

The basic components of a regular expression include literal characters, metacharacters, quantifiers, and anchors. Literal characters are the characters that are matched exactly as they appear. Metacharacters are symbols that have a special meaning in regular expressions. Quantifiers specify how many times a character or group of characters should appear. Anchors are used to match a position within a string.

3. How can I test a regular expression?

There are various online tools and software programs available for testing regular expressions. These tools allow you to enter a regular expression and a sample string, and then show you the matches and substitutions. Some popular tools include Regex101, RegExr, and RegexBuddy.

4. Can regular expressions be used in all programming languages?

Yes, regular expressions can be used in most programming languages, including Java, Python, JavaScript, and C++. However, the syntax and capabilities may vary slightly between languages.

5. Are regular expressions case-sensitive?

Yes, regular expressions are case-sensitive by default. This means that uppercase and lowercase letters are treated as different characters. However, most regular expression engines have an option to make the matching case-insensitive.

Similar threads

Replies
2
Views
1K
Replies
1
Views
2K
  • Introductory Physics Homework Help
2
Replies
41
Views
3K
  • Precalculus Mathematics Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
5K
  • Precalculus Mathematics Homework Help
Replies
13
Views
3K
  • Math Proof Training and Practice
2
Replies
39
Views
10K
Back
Top