Regex to with whitespace or tab or newline, can't seem to get it towork.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DotNetNewbie

    Regex to with whitespace or tab or newline, can't seem to get it towork.

    Hi,

    I have text in a file that looks like this:


    [
    2
    in stock]



    What kind of regex could get the '2' ?


    I tried this:

    string regex = @"[\s]*(?'stock'.*?). *in\sstock]";

    But it didn't work since [\s]* doesn't include tabs etc, and I am not
    sure exactly what that whitespace is.....
  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: Regex to with whitespace or tab or newline, can't seem to getit to work.

    DotNetNewbie wrote:
    I have text in a file that looks like this:
    >
    >
    [
    2
    in stock]
    >
    >
    >
    What kind of regex could get the '2' ?
    Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !

    Arne

    Comment

    • DotNetNewbie

      #3
      Re: Regex to with whitespace or tab or newline, can't seem to get itto work.

      On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
      DotNetNewbie wrote:
      I have text in a file that looks like this:
      >
      [
      2
      in stock]
      >
      What kind of regex could get the '2' ?
      >
      Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
      >
      Arne
      \d+ is for digits, but that area might contain whitespace, tabs or
      carriage returns also.

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: Regex to with whitespace or tab or newline, can't seem to getit to work.

        DotNetNewbie wrote:
        On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
        >DotNetNewbie wrote:
        >>I have text in a file that looks like this:
        >>[
        >> 2
        >> in stock]
        >>What kind of regex could get the '2' ?
        >Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
        >
        \d+ is for digits, but that area might contain whitespace, tabs or
        carriage returns also.
        If it contains whitespace then what do you want returned ?

        Arne

        Comment

        • DotNetNewbie

          #5
          Re: Regex to with whitespace or tab or newline, can't seem to get itto work.

          On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
          DotNetNewbie wrote:
          On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
          DotNetNewbie wrote:
          >I have text in a file that looks like this:
          >[
          > 2
          > in stock]
          >What kind of regex could get the '2' ?
          Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
          >
          \d+ is for digits, but that area might contain whitespace, tabs or
          carriage returns also.
          >
          If it contains whitespace then what do you want returned ?
          >
          Arne
          The integer value 2.

          Comment

          • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

            #6
            Re: Regex to with whitespace or tab or newline, can't seem to getit to work.

            DotNetNewbie wrote:
            On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
            >DotNetNewbie wrote:
            >>On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
            >>>DotNetNewb ie wrote:
            >>>>I have text in a file that looks like this:
            >>>>[
            >>>> 2
            >>>> in stock]
            >>>>What kind of regex could get the '2' ?
            >>>Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
            >>\d+ is for digits, but that area might contain whitespace, tabs or
            >>carriage returns also.
            >If it contains whitespace then what do you want returned ?
            >
            The integer value 2.
            If it does not contain any digits but only whitespace at that
            position you want it to return 2 ??

            Arne

            Comment

            • DotNetNewbie

              #7
              Re: Regex to with whitespace or tab or newline, can't seem to get itto work.

              On Mar 8, 8:53 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
              DotNetNewbie wrote:
              On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
              DotNetNewbie wrote:
              >On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
              >>DotNetNewbi e wrote:
              >>>I have text in a file that looks like this:
              >>>[
              >>> 2
              >>> in stock]
              >>>What kind of regex could get the '2' ?
              >>Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
              >\d+ is for digits, but that area might contain whitespace, tabs or
              >carriage returns also.
              If it contains whitespace then what do you want returned ?
              >
              The integer value 2.
              >
              If it does not contain any digits but only whitespace at that
              position you want it to return 2 ??
              >
              Arne
              The text is like this:

              [
              2
              in stock]

              All that whitespace could be: 1) whitespace 2)carriage return 3) tabs

              I want to extract the integer value (in the example I'm giving it is
              2).

              Comment

              • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                #8
                Re: Regex to with whitespace or tab or newline, can't seem to getit to work.

                DotNetNewbie wrote:
                On Mar 8, 8:53 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                >DotNetNewbie wrote:
                >>On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                >>>DotNetNewb ie wrote:
                >>>>On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                >>>>>DotNetNewb ie wrote:
                >>>>>>I have text in a file that looks like this:
                >>>>>>[
                >>>>>> 2
                >>>>>> in stock]
                >>>>>>What kind of regex could get the '2' ?
                >>>>>Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
                >>>>\d+ is for digits, but that area might contain whitespace, tabs or
                >>>>carriage returns also.
                >>>If it contains whitespace then what do you want returned ?
                >>The integer value 2.
                >If it does not contain any digits but only whitespace at that
                >position you want it to return 2 ??
                >
                The text is like this:
                >
                [
                2
                in stock]
                >
                All that whitespace could be: 1) whitespace 2)carriage return 3) tabs
                >
                I want to extract the integer value (in the example I'm giving it is
                2).
                \s matches space, CR and TAB !

                So I do still not understand the problem.

                Arne

                Comment

                • DotNetNewbie

                  #9
                  Re: Regex to with whitespace or tab or newline, can't seem to get itto work.

                  On Mar 8, 11:15 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                  DotNetNewbie wrote:
                  On Mar 8, 8:53 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                  DotNetNewbie wrote:
                  >On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                  >>DotNetNewbi e wrote:
                  >>>On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
                  >>>>DotNetNewbi e wrote:
                  >>>>>I have text in a file that looks like this:
                  >>>>>[
                  >>>>> 2
                  >>>>> in stock]
                  >>>>>What kind of regex could get the '2' ?
                  >>>>Try @"(\d+)(?:\s +in stock)" or @"(\d+)(?:\s+in \s+stock)" !
                  >>>\d+ is for digits, but that area might contain whitespace, tabs or
                  >>>carriage returns also.
                  >>If it contains whitespace then what do you want returned ?
                  >The integer value 2.
                  If it does not contain any digits but only whitespace at that
                  position you want it to return 2 ??
                  >
                  The text is like this:
                  >
                  [
                  2
                  in stock]
                  >
                  All that whitespace could be: 1) whitespace 2)carriage return 3) tabs
                  >
                  I want to extract the integer value (in the example I'm giving it is
                  2).
                  >
                  \s matches space, CR and TAB !
                  >
                  So I do still not understand the problem.
                  >
                  Arne
                  Ok I got it to work!

                  Comment

                  Working...