0

The input accepts data in format: %'letter' separator %'letter' and so on.

The separator can be: space, tab, colon or new line

Example:

%d %F %S   
or     
%d:%F:%S    
or    
%d:%F
%S

where the character after the '%' can be any letter

You cannot write something like:

%dddd %F %S
or 
%%d %F %S

So far I have done this:

^((%([a-zA-Z]){1})+\s?|:)+$

Any help will be appreciated.

2 Answers 2

2

How about

^((%[A-z])(\s|:))*(%[A-z])$

http://regexr.com?37626

Sign up to request clarification or add additional context in comments.

2 Comments

This allows: %d%d which is not valid
I've added the line begin and line termination, now it should work
1

You can go with this

(%[a-zA-Z][ \t\n;])*%[a-zA-Z]

Regular expression visualization

But I'd suggest passing an case-insensitive flag to your matcher. Then the expression can be shortened to

(%[a-z][ \t\n;])*%[a-z]

1 Comment

This allows to have %d %d%d. Every pair of %'letter' should have a separator between them, except the last one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.