how to check the format of a string ?

Hello, Im still busy with CIS 194 Now im facing this problem. There is a log file of strings. Most of them are of this format char Number [chars] What is the best way to check if the string has this format ? Regex or another way ? Roelof

If the format is sufficiently simple a regex can be a very neat way to
express the idea. Mostly people use parser combinators. Have a look at
parsec / attoparsec on hackage.
Ben
On Sun Feb 22 2015 at 18:50:18 Roelof Wobben
Hello,
Im still busy with CIS 194
Now im facing this problem.
There is a log file of strings.
Most of them are of this format char Number [chars]
What is the best way to check if the string has this format ?
Regex or another way ?
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

The exercise was meant to be done without using any library. Try it out, it
will work.
A parser combinator library, such as parsec or attoparsec is better learnt
after you have some idea of monads, which is the last topic cis194 deals
with.
But, if it interests you, keep going. Parsec might be a better option as it
has been there for a longer amount of time, and thus has more learning
resources.
Hope this helps.
On 23 February 2015 at 00:52, Roelof Wobben
Thanks,
Found this tutorial which works with log files like I have to do : https://www.fpcomplete.com/school/starting-with-haskell/libraries-and-framew...
Roelof
Benjamin Edwards schreef op 22-2-2015 om 20:14:
If the format is sufficiently simple a regex can be a very neat way to express the idea. Mostly people use parser combinators. Have a look at parsec / attoparsec on hackage.
Ben
On Sun Feb 22 2015 at 18:50:18 Roelof Wobben
wrote: Hello,
Im still busy with CIS 194
Now im facing this problem.
There is a log file of strings.
Most of them are of this format char Number [chars]
What is the best way to check if the string has this format ?
Regex or another way ?
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat

Also, as far as I remember, cis194 made you build parser combinators like parsec and attoparsec when teaching applicative functors and other fancy stuff. You can opt to wait till then. On 23 February 2015 at 00:55, Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13@iitbhu.ac.in> wrote:
The exercise was meant to be done without using any library. Try it out, it will work. A parser combinator library, such as parsec or attoparsec is better learnt after you have some idea of monads, which is the last topic cis194 deals with. But, if it interests you, keep going. Parsec might be a better option as it has been there for a longer amount of time, and thus has more learning resources.
Hope this helps.
On 23 February 2015 at 00:52, Roelof Wobben
wrote: Thanks,
Found this tutorial which works with log files like I have to do : https://www.fpcomplete.com/school/starting-with-haskell/libraries-and-framew...
Roelof
Benjamin Edwards schreef op 22-2-2015 om 20:14:
If the format is sufficiently simple a regex can be a very neat way to express the idea. Mostly people use parser combinators. Have a look at parsec / attoparsec on hackage.
Ben
On Sun Feb 22 2015 at 18:50:18 Roelof Wobben
wrote: Hello,
Im still busy with CIS 194
Now im facing this problem.
There is a log file of strings.
Most of them are of this format char Number [chars]
What is the best way to check if the string has this format ?
Regex or another way ?
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards
Sumit Sahrawat
-- Regards Sumit Sahrawat

On 2015-02-22 19:50, Roelof Wobben wrote:
Now im facing this problem.
There is a log file of strings.
Most of them are of this format char Number [chars]
What is the best way to check if the string has this format ?
For this particular format I'd go for plain pattern matching and guards. Something like import Data.Char (isLetter, isDigit) isValid :: String -> Bool isValid s = go (words s) where go ([a]:b:_) = isLetter a && all isDigit b go _ = False This will accept lines starting with a letter followed by some number and then (optionally!) some more text. -- Frerich Raabe - raabe@froglogic.com www.froglogic.com - Multi-Platform GUI Testing

Frerich Raabe schreef op 22-2-2015 om 20:38:
On 2015-02-22 19:50, Roelof Wobben wrote:
Now im facing this problem.
There is a log file of strings.
Most of them are of this format char Number [chars]
What is the best way to check if the string has this format ?
For this particular format I'd go for plain pattern matching and guards. Something like
import Data.Char (isLetter, isDigit)
isValid :: String -> Bool isValid s = go (words s) where go ([a]:b:_) = isLetter a && all isDigit b go _ = False
This will accept lines starting with a letter followed by some number and then (optionally!) some more text.
Thanks, I can also check if a is equal to I , W or E. And in the main function check if A = I/W/E Roelof
participants (4)
-
Benjamin Edwards
-
Frerich Raabe
-
Roelof Wobben
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)