logo
down
shadow

C++ spliting string by delimiters and keeping the delimiters in result


C++ spliting string by delimiters and keeping the delimiters in result

By : user2953253
Date : November 20 2020, 01:01 AM
fixed the issue. Will look into that further You could build your solution on top of the example for regex_iterator. If, for example, you know your delimiters are comma, period, semicolon, and hyphen, you could use a regex that captures either a delimiter or a series of non-delimiters:
code :
([.,;-]|[^.,;-]+)
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  // the following two lines are edited; the remainder are directly from the reference.
  std::string s ("aaa,bbb.ccc,ddd-eee;");
  std::regex e ("([.,;-]|[^.,;-]+)");   // matches delimiters or consecutive non-delimiters

  std::regex_iterator<std::string::iterator> rit ( s.begin(), s.end(), e );
  std::regex_iterator<std::string::iterator> rend;

  while (rit!=rend) {
    std::cout << rit->str() << std::endl;
    ++rit;
  }

  return 0;
}


Share : facebook icon twitter icon
Split string with various delimiters while keeping delimiters

Split string with various delimiters while keeping delimiters


By : user3311686
Date : March 29 2020, 07:55 AM
seems to work fine I have the following string: , Assuming those are your only separators then you can do this:
code :
var string = "dogs@cats^horses^fish!birds";
string.replace(/(@|\^|!)/g, '|$1').split('|');
How to split string on multiple delimiters keeping some delimiters?

How to split string on multiple delimiters keeping some delimiters?


By : looping
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , i'm looking for a way to split a string in several words, based on some delimiters. , Try this:
code :
$src='word1&word2 !word3 word4 &word5';
$arr=explode(' ',$src=preg_replace('/(?<=[\w])([&!])/',' $1',$src));
echo join('<br>',$arr); // present the result ...
Split a string with multiple delimiters while keeping these delimiters

Split a string with multiple delimiters while keeping these delimiters


By : user3925011
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The regex for splitsplitting on optional spaces after a word boundary is
code :
\\b\\s*
String str = "a| b |c& d^ e|f";
String regex = "\\b\\s*";
String[] spts = str.split(regex);
    for(int i =0; i < spts.length && i < 20; i++)
    {
        System.out.println(spts[i]);
    }
How do I split a string on different delimiters, but keeping on the output some of said delimiters? (Tokenize a string)

How do I split a string on different delimiters, but keeping on the output some of said delimiters? (Tokenize a string)


By : Markuens
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , More specifically I want to split a string on any non alpha-numeric character but in the case that the delimiter is not a white space I want to keept it. That is, to the input: , You may use
code :
import re
my_string = "Hey, I'm 9/11 7-11"
print(re.findall(r'\w+|[^\w\s]', my_string))
# => ['Hey', ',', 'I', "'", 'm', '9', '/', '11', '7', '-', '11']
JavaScript String split with multiple delimiters while keeping the delimiters

JavaScript String split with multiple delimiters while keeping the delimiters


By : user2667619
Date : March 29 2020, 07:55 AM
will be helpful for those in need The delimiters you actually want to split by are spaces, specifically, spaces that are followed by name:, id: or desc:.
Following this logic, this regex can be constructed:
code :
/ (?=name:|id:|desc)/i
console.log("id:123 name:test pumpe desc:pumpe p123".split(/ (?=name:|id:|desc)/i))
Related Posts Related Posts :
  • Transforming an expression template tree
  • How to overload an operator with multiple parameters like a + b + c?
  • C++ 11 with Raspberry Pi performances
  • Make a C++ class look like a numpy array using swig
  • Postfix incrementer overloading for nested enumerated types
  • Is there a tidy way of associating metadata with functions in C++
  • QObject::installEventFilter(): Cannot filter events for objects in a different thread
  • LNK2005 error with Zxing C++
  • C++ Doubly Linked List with Pointers: Object of class isn't constructed properly
  • Using a random string generator in c++ constructor
  • What should I use instead of void as one of the alternative types in an variant?
  • C++ return value from multithreads using reference
  • How to connect multiple TCP IP clients to same server port using c++
  • Defaul compiler generates the reference operator (In C++)?
  • Unable to change directory time stamp after using FILE_FLAG_BACKUP_SEMANTICS
  • vector handling displaying output
  • WSAGetLastError returns WSAENOTSOCK - Cause?
  • C++: How to overload pow for user type?
  • C++ using arrays as multidimensional despite initalising it as 1D with pointer
  • How negate std::is_integral for use in tag dispatch?
  • Retrieve serial number from USB memory (Windows environment c++)
  • g++ error: invalid preprocessing directive #INCLUDE
  • C++ What is the std::for_each() function parameter type?
  • C++: Read individual lines from text file, sort words alphabetically
  • Saving 'this' address into a variable
  • c++ command line arguments in ubuntu terminal
  • Convert "Cartesian coordinates" to "polar coordinates with respect to user specified origin"
  • In what order are local scoped objects destructed?
  • How to use SDL_MapRGB with SDL 2.0
  • how compiler and interpreter work in case of array declaration
  • GSL integration behaves strange
  • Cropping an image with OpenCV and C
  • Find the last line in text file and select the first 10 char and print to a new file?
  • Created many CCSprits but when triggering ccTouchBegan gives the last one allways
  • seekp and seekg don't work with fstream
  • Taking input in Sublime Text 3
  • ld: -bind_at_load and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
  • C++ storing #define as std::string would give size as zero compile time
  • How to use static linking with OpenSSL in C/C++
  • What is the difference between a trap, an error, a failure and program abortion?
  • Dynamic members allocation in qt
  • How to reduce object file size when compiling for VxWorks 5.5.1?
  • Printing char by integer qualifier
  • How to write code to be executed before main() gets control?
  • Blocking socket - waitForReadyRead()
  • std::string related errors and handling them, c++
  • VM interpreter - weighting performance benefits and drawbacks of larger instruction set / dispatch loop
  • C / C++ SHIFT / OFFSET / MOVE a Bitmap to the LEFT or RIGHT?
  • Printing numbers column by column
  • How do you change your app icon in visual studio 2013?
  • Fast Screen Transfer
  • c++ Read text file and input the numbers into a 2D array
  • Why are my C++ pointers suddenly diverging?
  • Is there a macro-based adapter to make a functor from a class?
  • CRTP and multilevel inheritance
  • How to implement timer for each object in c++?
  • Stuck when testing custom list class in c++
  • Using each member of class within one function to calculate average
  • check whether if two squares are intersecting with each other
  • Glm Quaternion lookat function
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org