According to my textbook, the same pre-mRNA sequence can get spliced in multiple different ways. But how is this regulated by the cell? How are the introns and exons to be spliced determined?
Your question is a good one, and has given rise to decades of intensive research, which continues today. The short answer is that many factors are involved, ranging from sequences within the gene up to chromatin-level changes.
De Conti et al. in their review "Exon and intron definition in pre-mRNA splicing" (2012 DOI: 10.1002/wrna.1140) note:
Most importantly, these influences act across several levels of complexity starting from the relatively simple interaction between two consensus 5' and 3' splice sites to much more complex factors: such as the interplay between silencer or enhancer sequences, transcriptional processivity, genomic milieu, nucleosome positioning, and histone modifications at the chromatin level. Depending on local contexts, all these factors will act either antagonistically or synergistically to decide the exon/intron fate of any given RNA sequence.
In the big-picture view, there are two types of intron-processing complexes or "spliceosomes" found in most metazoan cells. Akinyi and Frilander ("At the Intersection of Major and Minor Spliceosomes: Crosstalk Mechanisms and Their Impact on Gene Expression" 2021 DOI: 10.3389/fgene.2021.700744 ) summarize:
The majority of introns (more than 99.5% in humans) are recognized and excised by the major spliceosome, which utilizes relatively poorly conserved sequence elements at the 5' and 3' ends of the intron that are used for intron recognition and in subsequent catalysis. In contrast, the minor spliceosome targets a rare group of introns (approximately 0.5% in humans) with highly conserved sequences at the 5' and 3' ends of the intron.
Finally, it now seems clear that intron/exon structure developed at roughly the same time as eukaryotic cells. Rogozin et al. ("Origin and evolution of spliceosomal introns" 2012 DOI: 10.1186/1745-6150-7-11 ) write:
Reconstructions of intron gain and loss using the growing collection of genomes of diverse eukaryotes and increasingly advanced probabilistic models convincingly show that the LECA (Last Eukaryotic Common Ancestor) and the ancestors of each eukaryotic supergroup had intron-rich genes ...
There is no indication that any prokaryote has ever possessed a spliceosome or introns in protein-coding genes, other than relatively rare mobile self-splicing introns.
Here's a review of the molecular machinery at work: "The nuts and bolts of the endogenous spliceosome" Sperling 2017 DOI: 10.1002/wrna.1377